shell結合expect進行批量更改root密碼.txt

shell結合expect進行批量更改root密碼

[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 ######

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章