I am trying to connect to my router through telnet using this script:
#!/usr/bin/expect -f
set timeout 20
# router user name
set name "admin"
# router password
set pass "admin"
# router IP address
set routerip "192.168.1.1"
# Read command as arg to this script
set routercmd "cat /var/1.leases"
# start telnet
spawn telnet $routerip
# send username & password
expect "username:"
send -- "$name\n"
expect "password:"
send -- "$pass\n"
# get out of ISP's Stupid menu program, go to shell
expect "TBS>>"
send -- "sh\n"
# execute command
expect -re ".*\$"
send -- "$routercmd\n"
# exit
send -- "^D"
Now the script works fine up to the send -- "sh\n" part. It gets to the shell prompt which appears like : ~ $ (tilda-space-dollar-space). However, I am unable to issue the command after this. It basically just doesn't work after that.
Can anybody tell why? Is their some mistake I am making?