使用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
posted @ 2020-12-07 17:20  frantzz  阅读(243)  评论(0编辑  收藏  举报