I have the following scripts which is supposed to pull the IP address from a file device-list.txt
and then telnet to the device, login and execute a show run. The script logs in to the device successfully, but gives me an error after that. Any ideas where im going wrong?
for device in `cat device-list.txt`; do ./test4 $device;done
cat test4
#!/usr/bin/expect -f
set hostname [lindex $argv 0]
set user myusername
set pass mypassword
set timeout 10
log_file -a ~/results.log
send_user "\n"
send_user ">>>>> Working on $hostname @ [exec date] <<<<<\n"
send_user "\n"
spawn telnet $hostname
expect "Username:"
send "$user\n"
expect "Password:"
send "$pass\n"
expect "#"
send “term len 0\n”
send “show running-config\n”
expect “end\r”
send “\n”
send “exit\n”
User Access Verification
Username: myusername
Password:
ROUTER#usage: send [args] string
while executing
"send “term len 0\n”"
(file "./test4" line 26)
Your problem is due to incorrect double quotes. You have to use double quotes
"
, not smart quotes“
Note :
Basically,
Expect
will work with two feasible commands such assend
andexpect
. Ifsend
is used, then it is mandatory to haveexpect
(in most of the cases) afterwards. (while the vice-versa is not required to be mandatory)This is because without that we will be missing out what is happening in the spawned process as
Expect
will assume that you simply need to send one string value and not expecting anything else from the session.So, we recommend to use
expect
after eachsend
, to make sure our commands actually sent to the spawned process. (You have not usedexpect
after sending some commands such asterm len 0\r
). Also, use\r
instead of\n
.