networking - Bash and expect: can't reboot router via telnet -


i'm trying reboot d-link router connecting via telnet through expect. problem can't execute (through expect script) of commands supported router.

first of all, show short telnet session router:

telnet 192.168.1.1 trying 192.168.1.1... connected 192.168.1.1. escape character '^]'. bcm96338 adsl router login: admin password:  > swversion show eu_3-12-01-1r00.a2pb026.d20m > logout  bye bye. have nice day!!! connection closed foreign host. 

now i'm trying make automatic expect script can't make work. here's script:

#!/usr/bin/expect -f  #exp_internal 1 set timeout 30  #router username set name admin  #command execute set routercmd "swversion show"  #router password set pass mypassword  #router ip address set routerip 192.168.1.1  spawn telnet $routerip # send username & password expect "login: " send "$name\r" expect "password: " send "$pass\r" expect "> " send "$routercmd\r" expect "> " 

when execute script, gets stuck @ password prompt:

./reboot_dut.sh  spawn telnet 192.168.1.1 trying 192.168.1.1... connected 192.168.1.1. escape character '^]'. bcm96338 adsl router login: admin password:  

if uncomment #exp_internal 1 line get:

./reboot_dut.sh  spawn telnet 192.168.1.1 parent: waiting sync byte parent: telling child go ahead parent: unsynchronized child spawn: returns {6398}  expect: "" (spawn_id exp7) match glob pattern "login: "? no trying 192.168.1.1... expect: "trying 192.168.1.1..." (spawn_id exp7) match glob pattern "login: "? no   expect: "trying 192.168.1.1...\r\n" (spawn_id exp7) match glob pattern "login: "? no connected 192.168.1.1. expect: "trying 192.168.1.1...\r\nconnected 192.168.1.1." (spawn_id exp7) match glob pattern "login: "? no   expect: "trying 192.168.1.1...\r\nconnected 192.168.1.1.\r\n" (spawn_id exp7) match glob pattern "login: "? no escape character '^]'. expect: "trying 192.168.1.1...\r\nconnected 192.168.1.1.\r\nescape character '^]'." (spawn_id exp7) match glob pattern "login: "? no   expect: "trying 192.168.1.1...\r\nconnected 192.168.1.1.\r\nescape character '^]'.\r\n" (spawn_id exp7) match glob pattern "login: "? no bcm96338 adsl router  expect: "trying 192.168.1.1...\r\nconnected 192.168.1.1.\r\nescape character '^]'.\r\nbcm96338 adsl router\r\n" (spawn_id exp7) match glob pattern "login: "? no login:  expect: "trying 192.168.1.1...\r\nconnected 192.168.1.1.\r\nescape character '^]'.\r\nbcm96338 adsl router\r\nlogin: " (spawn_id exp7) match glob pattern "login: "? yes expect: set expect_out(0,string) "login: " expect: set expect_out(spawn_id) "exp7" expect: set expect_out(buffer) "trying 192.168.1.1...\r\nconnected 192.168.1.1.\r\nescape character '^]'.\r\nbcm96338 adsl router\r\nlogin: " send: sending "admin\r" { exp7 }  expect: "" (spawn_id exp7) match glob pattern "password: "? no expect: "a" (spawn_id exp7) match glob pattern "password: "? no dmin password:  expect: "admin\r\npassword: " (spawn_id exp7) match glob pattern "password: "? yes expect: set expect_out(0,string) "password: " expect: set expect_out(spawn_id) "exp7" expect: set expect_out(buffer) "admin\r\npassword: " send: sending "mypassword\r" { exp7 }  expect: "" (spawn_id exp7) match glob pattern "> "? no expect: timed out send: sending "swversion show\r" { exp7 }  expect: "" (spawn_id exp7) match glob pattern "> "? no  > swversion show  expect: "\r\n> swversion show\r\n" (spawn_id exp7) match glob pattern "> "? yes expect: set expect_out(0,string) "> " expect: set expect_out(spawn_id) "exp7" expect: set expect_out(buffer) "\r\n> " 

solution: found solution problem. router trying reboot d-link 2640b. working expect script router is:

#!/usr/bin/expect -f  spawn telnet router_ip match_max 10000 expect *login:* sleep 2 send -- "username\r" expect *assword:* sleep 2 send -- "password\r" expect *>* send -- "\r" expect *>* send -- "command\r" expect *>* send -- "\r" expect *>* send -- "logout\r" 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -