set commands {
"show phone xxx 11"
"show phone yyy 22"
"show phone zzz 33"
}
spawn ssh -o StrictHostKeyChecking=no $UserId@$host
sleep 15
#wait for password prompt
expect "*assword:"
#send password
send -- "$Passwd\r"
sleep 5
foreach cmd $commands {
set logfile [join [lrange [split $cmd] 2 end] _]
log_file -a $logfile
send -- "$cmd\r"
expect -re "admin:"
exp_sleep 8
log_file
}
was not able redirect command's output to respective log file.
xxx_11 log file contains 'spawn ssh -o StrictHostKeyChecking=no $UserId@$host' output.
yyy_22 log file contains 'show phone xxx 11' command output.
zzz_33 log file contains 'show phone yyy 22' command output.
How to write log files in the following way:
XXX_11 log file contains 'show phone xxx 11' command output
yyy_22 log file contains 'show phone yyy 22' command output
zzz_33 log file contains 'show phone zzz 33' command output
Thanks in adavnce for help.
sleep. If you find you need tosleep, your patterns are wrong, and you should useexpect -d scriptto debug the patterns.