Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Community Member

Error Expect script

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Member

Did you resolve the issue?. I

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

3 REPLIES
Community Member

Did you resolve the issue?. I

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

Community Member

Dear Javier,

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

Community Member

Seems to be a buffer issue or

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

326
Views
0
Helpful
3
Replies
CreatePlease to create content