Expect Scripting Help

Hi All,

I am suppose to capature the value command `show ip route` of a router in a Expect script. But i am not able to catch the value in a variable or a file in the following Expect script.

#!/usr/bin/expect -f
set input [open "/root/output.txt" "w"]
spawn telnet localhost $argv
expect "Escape character is '^]'."
expect -re "Connected (.)\n"
send "\r"
expect "> "
send "enable\r"
expect "Password: "
send "route\r"
expect "# "
# exec "show ip route" >@ $input
send "show ip route\r"
expect -re "(.
)\n"
set outcome $expect_out(0,string)
# send $outcome
puts $input $outcome
expect "# "
send "exit\r"
close $input

Please help me debug a script.

Regards,
Harikrishna.

exp_internal 1

turns on verbose output

Hi Jerry,
Thanks for your suggestion.My script worked. Now i am doing the script for `show run` for router.But i want to remove the `!` character that is getting stored in the output file. How to ignore `!` character and replace it by blank space.

Below pasted the current output what i am getting.

Current configuration : 1094 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R2
!
boot-start-marker
boot-end-marker

I need output like this

Current configuration : 1094 bytes
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
hostname R2
boot-start-marker
boot-end-marker

This is my script:

#!/usr/bin/expect -f
spawn telnet localhost $argv
expect "Escape character is '^]'."
expect -re "Connected (.)\n"
send "\r"
expect "> "
send "enable\r"
expect "Password: "
send "rout\r"
expect "# "
match_max 40000
set output [open "/root/output2.txt" "w"]
send "terminal length 0\r"
expect "# "
expect "
"
send "show run\r"
expect -re "Building configuration (.)"
expect -indices -re ".+"
expect -re "\r\n(.*)\r(.
)(\\\$ |# )"
set outcome $expect_out(buffer)
send "\r"
puts $output $outcome

Please help me debug the script.

whatever output you get, pipe it to grep -v "!" :stuck_out_tongue:

This ( grep -v "!" )does not help in Expect scripting.. Can you suggest me some other way Please.

Regards,
Srezee.

I dont knw anythng abt ur script ..

To remove the ! in the output u can do somethng like below ,by redirecting output to of ur script to awk.

awk '!/^!$/ { print}'