Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to create a script, which will automatically log me into router. I have created the following script but I cannot get it to work. Here is the script.
~~~~~~~~~~~~~~~~~~~~~~~~~
#!/opt/local/bin/expectlog_user 1
set rtr $argv
set login_id "username"
set pswd "password"
#append rtr ".ip"
spawn telnet $rtr
expect {" login:" { send "$login_id\r" }
"Username:" { send "$login_id\r" }
"login:" { send "$login_id\r" }
"RETURN" { send "\r\r" }
}
expect "assword:" { send "$pswd\r" }
interact
~~~~~~~~~~~~~~~~~~~~~~~~~I have named the file, router.
I also issued chmod u+x router to make it executable.Can anyone tell me if there is another step that I am missing or if there is something wrong with the script.
Thanks
Asad

Turn on the verbose mode. I'll have a better answer for you in the a.m. It looks like your send, expect section is incorrect.
Try running 'autoexpect' as a macro recorder then doing manually all the steps you want to repeat. It will show you what it needs to do.

Here is a working code snippet. BTW 'send "\x1d\x0d"' is the same as cntrl - ].
while { $n < 5 } {
spawn "/bin/sh"
send "telnet $LOCALHOST\r"
sleep 1
expect "ogin"
send "$username\r"
expect "Password"
send "$password\r"
send "\r\r"
"Welcome" {
incr pass0
set n 5
set p 0
close
}
"from" {
send "id\r"
expect {
$username {
incr pass0
set n 5
close
}
}
}
"login: $" {
set pass1 0
puts stdout "Expect return: $expect_out(0,string)"
puts stdout "Failed login"
send "\x1d\x0d"
expect "telnet"
send "close\r"
send "quit\r"
close
}
}
incr n
}

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |