标签:shell
[root@server18 mnt]# vim ssh.exp
#!/usr/bin/expect
set timeout 2
set IP [ lindex $argv 0 ]
set PASS [ lindex $argv 1 ]
set COMM [ lindex $argv 2 ]
spawn ssh root@$IP $COMM
expect {
"yes/no"
{send "yes\r";exp_continue}
"password:"
{send "$PASS\r"}
{send "$COMM\r"}
}
expect eof
[root@server18 mnt]# vim create_user.sh
#!/bin/bash
for NUM in {1..33}
do
ping -c1 -w1 172.25.254.$NUM &> /dev/null && (
/mnt/ssh.exp 172.25.254.$NUM redhat &> /dev/null
done
if
[ -n "$1" -a -n "$2" ]
then
if
[ -e "$1" -a -e "$2" ]
then
MAXUSER=`wc -l $1 | cut -d " " -f 1`
MAXPASS=`wc -l $2 | cut -d " " -f 1`
[ "$MAXUSER" -eq "$MAXPASS" ]&&(
for NUM in $( seq 1 $MAXUSER )
do
USERNAME=`sed -n ${NUM}p $1`
PASSWORD=`sed -n ${NUM}p $2`
CKUSER=`getent passwd $USERNAME`
[ -z "$CKUSER" ]&&(
useradd $USERNAME
echo $PASSWORD | passwd -stdin $USERNAME
)||echo "$USERNAME exist !!!"
done
)||(
echo $1 and $2 have different lines
)
elif
[ ! -e "$1" ]
then
echo "ERROR:$1 is not exsit"
else
echo "ERROR:$2 is not exsit"
fi
else
echo "ERROR: Please input userfile and password file after command !!"
fi
本文出自 “12115084” 博客,请务必保留此出处http://12125084.blog.51cto.com/12115084/1883129
标签:shell
原文地址:http://12125084.blog.51cto.com/12115084/1883129