[root@p1 python]# cat /root/serverlist.txt 10.0.1.20 10.0.1.31 root@p1 python]# cat test.sh #!/bin/bash cat /root/serverlist.txt|while read line do echo "###$(date) changing $line 's user password ###" echo expect root.sh $line &> /dev/null done [root@p1 python]# cat root.sh #!/usr/bin/expect -f set ip [lindex $argv 0] set password hello123 set name root set cmd "echo hello \| passwd --stdin root" spawn ssh $name@$ip $cmd expect "root@$ip's password:" send "$password\r" expect eof [root@p1 python]# ./test.sh ###Fri Jan 18 16:49:42 CST 2013 changing pongo server 's user password ### ######Fri Jan 18 16:49:42 CST 2013 changing 10.0.1.20 's user password ###### ######Fri Jan 18 16:49:43 CST 2013 changing 10.0.1.31 's user password ###### 转载请保留固定链接: https://linuxeye.com/program/1245.html |