linuxexpect批量修改主机密码
ip.txt
192.168.0.105123455192.168.0.106123456
192.168.0.107123457
192.168.0.108123458
passwd.sh
#!/bin/bashfor ip in `awk"{print $1}" ip.txt`dopass
=`grep $ip ip.txt |awk"{print $2}"`echo $ip $passexpect action.exp $ip $pass
done
action.exp
#!/bin/expectset ip [lindex $argv
0]set
passwd [lindex $argv 1]set timeout
30spawn
ssh root@$ipexpect {
"yes/no" {send "yes";exp_continue}"password" {send "$passwd"}}
expect
"#"send
"echo 408950 |passwd --stdin root"send
"exit"expect eof
使用
[root@localhost ~]# shpasswd.sh192.168.0.105123456
spawn ssh root@192.168.0.105
root@192.168.0.105"s password:
Last login: Tue Jul 722:37:382020 from 192.168.0.104
[root@localhost ~]# echo123456 |passwd --stdin root
Changing password for user root.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# exit
logout
Connection to 192.168.0.105 closed.
原文链接:https://www.cnblogs.com/mu2i/archive/2020/07/07/13264102.html
以上是 linuxexpect批量修改主机密码 的全部内容, 来源链接: utcz.com/z/518153.html