有对端服务器root权限,进行对端服务器批量创建用户及密码
[root@node1 jtitsm]# pwd
/root/jtitsm
[root@node1 jtitsm]# cat changpass.sh
#!/bin/bash
for i in `awk '{print $1}' passwd.txt`
do
j=`awk -v I="$i" '{if(I==$1)print $2}' passwd.txt`
expect /root/jtitsm/login.exp $i $j
if [ $? == 0 ];then
echo "$i jtitsm create suceesful " >> /tmp/liuye.log
else
echo "$i jtitsm not create" >> /tmp/liuye.log
fi
done
[root@node1 jtitsm]# cat login.exp
#!/usr/bin/expect
set timeout 5
set ipaddress [lindex $argv 0]
set rootpass [lindex $argv 1]
spawn ssh shadm1@$ipaddress
expect {
"yes/no)?" { send "yes\r";exp_continue }
"assword:" { send "
shadm1用户密码\r" }
}
expect "*success*"
#send "LANG=en_US\r"
send "su -\r"
expect "assword:"
send "${rootpass}\r"
send "useradd jtitsm\r"
send "echo '
jtitsm用户密码'| passwd --stdin jtitsm\r"
send "su - jtitsm\r"
expect "*jtitsm@*" {send "exit\r";exit 0}
#expect eof
#send "exit\r"
passwd.txt 服务器ip及 root
阅读(1559) | 评论(0) | 转发(0) |