I am new to Expect and scripting in general. I am trying to make a few scripts to make my life a bit easier when pulling network device configurations. I managed to create a
I would do this (untested):
#!/usr/bin/expect -f
set logfile "/home/text.cfg[clock format [clock seconds] -format %Y%m%d]"
close [open $logfile w] ;# truncate the logfile if it exists
set ip_file "list.txt"
set fid [open $ip_file r]
while {[gets $fid ip] != -1} {
spawn ssh $ip -l admin
expect "Password:"
send "password\r"
expect "admin@"
send "set cli pager off\r"
log_file $logfile
send "show config running\r"
expect "admin@"
log_file
send "exit\r"
expect eof
}
close $fid
Notes:
\r
to simulate hitting enter when you send
commands.expect eof
after you send "exit"