LinuxEye - Linux系统教程

LinuxEye - Linux系统教程

当前位置: 主页 > 脚本编程 >

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

时间:2013-02-01 09:50来源:51CTO 编辑:hnzmdlyw 点击:
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
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 ######

转载请保留固定链接: https://linuxeye.com/program/1245.html

------分隔线----------------------------
标签:expectshell
栏目列表
推荐内容