使用expect实现自动化ssh以及批量修改密码
#!/bin/bash
for i in `cat /root/soft/ip.txt`
do
/usr/bin/expect << EOF
spawn /usr/bin/ssh root@$i
expect {
"UNIX password" { send "Huawei@123\r" }
}
expect {
"New password:" { send "xxHuzzawexxi@1234#\r" }
}
expect {
"Retype new password:" { send "xxHuzzawexxi@1234#\r" }
}
expect "*]#"
send "echo Huawei@123|passwd --stdin root\r"
expect "*]#"
send "exit\r"
expect eof
EOF
done

浙公网安备 33010602011771号