1、创建用户/密码对文件
# cat user.password
test1:123456789
test2:123456789 #=========END=======================================================
2、创建expect.sh脚本文件
# cat expect.sh
#!/usr/local/bin/expect
if {$argc<2} {
send_user "usage: $argv0 username password\n"
exit
}
set username [lindex $argv 0]
set password [lindex $argv 1]
send_user "execute:$argv0 $username $password\n"
spawn -noecho passwd [lindex $argv 0] #-noecho不回显spawn正在调用的命令
expect {
"*口令*" {send "$password\n"}
"*word*" {send "$password\n"}
}
expect {
"*口令*" {send "$password\n"}
"*word*" {send "$password\n"}
}
#expect "*word*"
#send "$password\n"
expect eof
exit
#=========END=======================================================
3、创建autochg.sh文件,在此文件中调用expect.sh
# cat autochg.sh
#!/usr/bin/bash
for i in `cat $1`
do
USERNAME=${i%:*} #自右起第一个冒号后的字符都不要
PASSWORD=${i#*:} #自左起第一个冒号前的字符都不要
./expect.sh $USERNAME $PASSWORD
done
#=========END=======================================================
# chmod u+x expect.sh autochg.sh
# ./autochg.sh user.password
阅读(1108) | 评论(0) | 转发(0) |