I am trying to automate switch commands. It's almost all good, but when the expect script reads each line from the file containing my switch commands (listed line by line), the switch seems to stop after about 10 or 15 commands, i think the buffer is too small.
How can I add in a sleep between each command that is read from the file? Thanks!!
set fp [open "/home/room.txt" r]
set data [read $fp]
set timeout -60
spawn telnet 10.91.60.14
match_max 100000
sleep 2
expect *
send -- "^Y"
sleep 2
send -- "password\r"
sleep 2
send -- "^[\[A"
send -- "^[\[A"
send -- "\r"
sleep 1
send -- "enable\r"
send -- "configure terminal\r"
sleep 1
expect *
sleep 2
**send -- "$data"**
sleep 2
interact
Best Answer
So, older discussion but after wrestling with
expect
over the past day or two and gathering several helpful hints from users here and elsewhere I decided to post what I had found. I am also on a Mac not native Linux for this so some things were quirky. This script is called from abash
script with:If
#!<PATH to expect> -f
is implemented in the top line of your*.expect
file AND you:chmod +x <filename>.expect
your file this will work. The-d
is for additional debug info.Call
expect
with:expect -df <filename>.expect
in your bash script to accomplish the same effect and you do not need executable rights on the file.The debug info is very helpful on seeing your
expect
statements, variables, etc. like this:Here is the short bash script, (only an example, but helpful if you need it to do more complex stuff or just call it from
bash
for some reason)Here is the
expect
script:Hopefully this helps some/anyone save some time out there!