第一次写博客,请各位多多指教,代码需要改进的地方,请留下您宝贵的建议。 <textarea readonly="readonly" name="code" class="shell"> #!/bin/bash #writer:LiCe oldpasswd=123abc newpasswd=123456 user=root port=22 for i in `cat /root/iplist.txt | awk '{print $1}'` do expect -c " set timeout 5 spawn ssh $user@$i -p $port ; expect { yes/no { send \"yes\r\"; exp_continue } *assword* { send \"$oldpasswd\r\"} }; expect root@* { send \"passwd\r\"; exp_continue }; expect { *assword* { send \"$newpasswd\r\"; exp_continue } *assword* { send \"$newpasswd\r\" } }; expect root@* { send exit\r }; expect eof; " done