05-09-2017 01:35 AM
Dear team,
I write expect script to check "show run", " show inventory", ... v.v . However, when the script run, it appear not enough log on file log. this is my code:
iplist:
Router's ip addresses
show.sh
#!/usr/bin/expect -f
#setup argument
set IPaddress [lindex $argv 0]
set Username "admin"
set Password "cisco123"
set enablepassword "cisco123"
set Directory /root/logs
log_file -a $Directory/session_$IPaddress.log
send_log "### /START-SSH-SESSION/ IP: $IPaddress @ [exec date] ###\r"
#telnet IP
spawn telnet $IPaddress
#login
expect "Username:"
send "$Username\n"
expect "Password:"
send "$Password\n"
expect ">"
send "en\n"
expect "Password:"
send "$enablepassword\n"
expect "#"
send "ter length 0\r"
expect "#"
expect *;
send "show running-config\r"
# send "show inventory\r"
expect "end"
send "exit"
send_log "\r### /END-SSH-SESSION/ IP: $IPaddress @ [exec date] ###\r"
exit
telnet.sh:
#!/bin/bash
while read ipadd
do
export ipadd
./show.sh $ipadd
sleep 1
done < iplist
Please help me check this log. Many thanks and look forward to team.
Solved! Go to Solution.
07-12-2017 03:36 PM
Did you resolve the issue?. I would rather redirect the output of the expect script to a log file, and then, filter out lines.
Javier
07-12-2017 03:36 PM
Did you resolve the issue?. I would rather redirect the output of the expect script to a log file, and then, filter out lines.
Javier
07-12-2017 07:11 PM
Dear Javier,
I have some problems with this code. Sometimes, it's miss information of command. For example, when I "show inventory" without code, it appears 10 lines, however I use this code, it appear 8 lines and miss 2 lines. Could you help me with this problem?
Many thanks and look forward to you
Tuan
07-13-2017 07:20 AM
Seems to be a buffer issue or terminal lenght command did not work properly.
I see some points
1.- Try changing expect command to following format:
send { ignore arg } "some command\r"
2.- Do not use "expect *". Instead use a larger string to compare the output (not only "#").
3.- Never use "#" character if you are expecting same character to compare with it.
Hope this helps,
Javier
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide