Quantcast
Viewing latest article 25
Browse Latest Browse All 157

Looking for assistance in expect

I have a bash script that has expect to login to a remote host and run list of commands. It works as expected. It has a flaw, if the user enters the wrong password, the expect script keeps trying the password for multiple times. Some host on network are now updated to block the newer ssh connection if there was multiple ssh failure in the recent for some minutes. I am trying to modify the script so the expect breaks/exits the code if the password is wrong on the first attempt.

echo "Enter the admin password:  "read passworditmp=$(mktemp)cat > $itmp << EOFset timeout 5spawn ssha -oStrictHostKeyChecking=no -oCheckHostIP=no admin@$hostnameset timeout 5expect "password"send "$password\r"expect "$hostname"send "command1\r"expect "$hostname"send "command2\r"expect "$hostname"send "command3\r"expect "$hostname"send "exit\r"expect eofEOFchmod 600 $itmpexpect -f $itmprm $itmp

Viewing latest article 25
Browse Latest Browse All 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>