您的位置:首页 > 运维架构 > Shell

shell结合expect进行批量更改root密码.txt

2013-01-31 13:18 555 查看
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 ######
本文出自 “成功来源于分享” 博客,请务必保留此出处http://linuxchina.blog.51cto.com/938835/1130159
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: