Posted to tcl by grummund at Wed Jul 04 19:07:39 GMT 2018view raw

  1. #!/usr/bin/expect
  2.  
  3. set user "engineer"
  4. set addr "router"
  5. set pass "[lindex $argv 0]"
  6.  
  7. spawn sshpass -p "$pass" ssh -o UserKnownHostsFile= -o StrictHostKeyChecking=no "$user@$addr"
  8.  
  9. set timeout 20
  10.  
  11. expect {
  12. timeout {
  13. puts "Connection timed out"
  14. exit 1
  15. }
  16.  
  17. "$user>" {
  18. send "help\r"
  19. }
  20.  
  21. "$user>" {
  22. send "exit\r"
  23. }
  24. }
  25.  
  26. What happens when the above script is run:
  27.  
  28. ~# ./reboot-adsl-router SEEKRET
  29. spawn sshpass -p SEEKRET ssh -o UserKnownHostsFile= -o StrictHostKeyChecking=no engineer@router
  30. engineer>~#
  31.  
  32. What happens for manual login from the command line:
  33.  
  34. ~# sshpass -p SEEKRET ssh -o UserKnownHostsFile= -o StrictHostKeyChecking=no engineer@router
  35.  
  36. After entering the above command the terminal is cleared and the following starts from top of screen:
  37.  
  38. | | o |
  39. |--- ,---. ,---. |---. ,---. . ,---. ,---. | ,---. ,---.
  40. | |---' | | | | | | | | | | | | |
  41. `---' `---' `---' ` ' ` ' ` `---' `---' `---' `---' `
  42. N E X T G E N E R A T I O N G A T E W A Y
  43. --------------------------------------------------------------------
  44. NG GATEWAY SIGNATURE DRINK
  45. --------------------------------------------------------------------
  46. * 1 oz Vodka Pour all ingredients into mixing
  47. * 1 oz Triple Sec tin with ice, strain into glass.
  48. * 1 oz Orange juice
  49. --------------------------------------------------------------------
  50.  
  51. Product: vant-8_r16-2
  52. Release: Jade (16.2)
  53. Version: 16.2.7064-2201011-20170207212801-d592e891575d5fd3ba62668fd85dd2574bca7b1e
  54.  
  55.  
  56. Hash config: d592e891575d5fd3ba62668fd85dd2574bca7b1e
  57. Hash openwrt: 246337582b1542cf5dbc0f9d2f19a0ea9500c4fc
  58. Hash kernel: d94a9b191cb4708f8b98dcb521298108ffd2f95a
  59. Hash custo: 01381b6688b690ce9a54355ec085ba000c1c4a0d
  60. Hash technicolor: fe192c9f4ab79625ff4986c7a42da854ebf6dd4e
  61. Hash lte: 546ac206f18443faf0e44720f4bfd28274f82851
  62. Hash mindspeed: 91b6a7a4d703268d6023c3a58da3d33fc62e7ed8
  63. Hash packages: f07af7c7968e10e3e707d03d755aec232cffc6ec
  64. ====================================================================================
  65. engineer>help
  66. AVAILABLE COMMANDS:
  67. ===================
  68. add (AddObject)
  69. apply
  70. count
  71. del (delete,DeleteObject)
  72. dmesg
  73. dsldiagd
  74. get (GetParameterValues,gpv,GPV)
  75. getpn (GetParameterNames,gpn,GPN)
  76. ifconfig
  77. ifstatus
  78. ip
  79. iptables
  80. list
  81. logread
  82. nslookup
  83. ping
  84. ps
  85. readlogfile
  86. reboot
  87. resolve
  88. route
  89. rtfd
  90. set (SetParameterValues,spv,SPV)
  91. stop
  92. subscribe
  93. tcpdump
  94. top
  95. traceroute
  96. ubuscall
  97. ubuslisten
  98. unsubscribe
  99. upgrade
  100. reload
  101. help
  102. exit
  103. engineer>exit
  104. Connection to router closed.
  105. ~#