Once spawn is completed for ssh, there could be several scenarios that can encountered. I'm trying to figure out how to handle most within a function and then move to the main part of the script i.e
Code:
spawn ssh -l us ser
#Do pattern match of what could be, possibly within a function somehow if possible and then move to the 2nd function which could be a set of commands.
expect "continue"
exp_send "yes\r"
expect "word"
exp_send "$crpP\r"
#Once successful then continue with some commands. This could be second function.
expect "$prompt"
exp_send "$cmd1\r"
....
exp_send "logout\r"