Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 157

Exiting an Expect Script

$
0
0

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 -fset timeout 10match_max 100000set hostname [lindex $argv 0]spawn /usr/bin/ssh -o "StrictHostKeyChecking no" admin@$hostnameexpect "*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.


Viewing all articles
Browse latest Browse all 157

Trending Articles



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