Posted to tcl by grummund at Wed Jul 04 19:07:39 GMT 2018view pretty
#!/usr/bin/expect set user "engineer" set addr "router" set pass "[lindex $argv 0]" spawn sshpass -p "$pass" ssh -o UserKnownHostsFile= -o StrictHostKeyChecking=no "$user@$addr" set timeout 20 expect { timeout { puts "Connection timed out" exit 1 } "$user>" { send "help\r" } "$user>" { send "exit\r" } } What happens when the above script is run: ~# ./reboot-adsl-router SEEKRET spawn sshpass -p SEEKRET ssh -o UserKnownHostsFile= -o StrictHostKeyChecking=no engineer@router engineer>~# What happens for manual login from the command line: ~# sshpass -p SEEKRET ssh -o UserKnownHostsFile= -o StrictHostKeyChecking=no engineer@router After entering the above command the terminal is cleared and the following starts from top of screen: | | o | |--- ,---. ,---. |---. ,---. . ,---. ,---. | ,---. ,---. | |---' | | | | | | | | | | | | | `---' `---' `---' ` ' ` ' ` `---' `---' `---' `---' ` N E X T G E N E R A T I O N G A T E W A Y -------------------------------------------------------------------- NG GATEWAY SIGNATURE DRINK -------------------------------------------------------------------- * 1 oz Vodka Pour all ingredients into mixing * 1 oz Triple Sec tin with ice, strain into glass. * 1 oz Orange juice -------------------------------------------------------------------- Product: vant-8_r16-2 Release: Jade (16.2) Version: 16.2.7064-2201011-20170207212801-d592e891575d5fd3ba62668fd85dd2574bca7b1e Hash config: d592e891575d5fd3ba62668fd85dd2574bca7b1e Hash openwrt: 246337582b1542cf5dbc0f9d2f19a0ea9500c4fc Hash kernel: d94a9b191cb4708f8b98dcb521298108ffd2f95a Hash custo: 01381b6688b690ce9a54355ec085ba000c1c4a0d Hash technicolor: fe192c9f4ab79625ff4986c7a42da854ebf6dd4e Hash lte: 546ac206f18443faf0e44720f4bfd28274f82851 Hash mindspeed: 91b6a7a4d703268d6023c3a58da3d33fc62e7ed8 Hash packages: f07af7c7968e10e3e707d03d755aec232cffc6ec ==================================================================================== engineer>help AVAILABLE COMMANDS: =================== add (AddObject) apply count del (delete,DeleteObject) dmesg dsldiagd get (GetParameterValues,gpv,GPV) getpn (GetParameterNames,gpn,GPN) ifconfig ifstatus ip iptables list logread nslookup ping ps readlogfile reboot resolve route rtfd set (SetParameterValues,spv,SPV) stop subscribe tcpdump top traceroute ubuscall ubuslisten unsubscribe upgrade reload help exit engineer>exit Connection to router closed. ~#