I have this expect
script, that will log into a host, run a command, return it's contents and exit. What sort of cleanup/proper exiting needs to happen when I've finished running my command? This command will always return something, the larger problem or issue I think I should be handling is if either SSH hangs, or if logging in as the admin user hangs. I thought I might have been handling that via timeout
, but I am unsure:
#!/usr/bin/expect -f
set timeout 10
match_max 100000
set hostname [lindex $argv 0]
spawn /usr/bin/ssh -o "StrictHostKeyChecking no" admin@$hostname
expect "password:"
send -- "redactedSSHpassword\r"
expect "Username:"
send -- "admin\r"
expect "password:"
send -- "redacted\r"
expect -- "#"
send -- "show stat summary\r"
expect -- "#"
I also don't understand the proper way of exiting this script and making sure I'm not leaving a stale session around.