Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to connect to a network router and execute show status on it.
Currently i am using:
spawn ssh -o StrictHostKeyChecking=no admin@192.168.20.254
expect " * ? password:*\r"
send -- "secretPassword\r"
sleep 5
send -- "show status\r"
sleep 10
send -- "exit\r"

It dosen't work, i get stuck at admin@192.168.20.254's password:i've tried entering the password but it does not work, i get:
server1:~# secretPassword
-bash: server1: command not found
server1:~#


What am i doing so wrong here ... ?

share|improve this question
    
I think you're just missing a suitable timeout see the edit to my answer. –  Iain Jan 14 '11 at 11:28

2 Answers 2

up vote 1 down vote accepted

Try doing it like this

#!/usr/bin/expect -f
set timeout 120
spawn ssh -o StrictHostKeyChecking=no admin@192.168.20.254
expect "*?assword:*"
send -- "secretPassword\r"
sleep 5
send -- "show status\r"
sleep 10
send -- "exit\r"
expect eof

If your device is slow to respond you probably need to set a suitable timeout.

share|improve this answer
    
that was it. the "set timeout 120" :) thank you so much ! –  s.mihai Jan 14 '11 at 13:45

First you should look at automating the whole process of collecting and tracking router information using RANCID instead of doing a one off solution.

For this particular issue, take a look at autoexpect to automate the creation of your expect script. That should give you a working expect script to start from. To fix your existing script, try running expect with the -d argument. That will show you exactly what expect is looking to match, and should hopefully tell you what is wrong in your match expression.

share|improve this answer
    
RANCID is not up to the job as it only monitors current configuration and i want to get some information regarding current bandwidth usage with this and then save it into a dv. (i can not use SNMP) –  s.mihai Jan 14 '11 at 6:00
    
Ok... but does my suggestion to use autoexpect and/or expect -d help? –  Phil Hollenback Jan 14 '11 at 6:29
    
i tried with <code>expect -d</code> and it worked... but no error message showed, after the sugestion from Iain to use <code>set timeout</code> it al works great now ! –  s.mihai Jan 14 '11 at 13:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.