Kitz ADSL Broadband Information
adsl spacer  
Support this site
Home Broadband ISPs Tech Routers Wiki Forum
 
     
   Compare ISP   Rate your ISP
   Glossary   Glossary
 
Please login or register.

Login with username, password and session length
Advanced search  

News:

Author Topic: Expect script to stop BTAgent in HG612 router  (Read 2521 times)

broadstairs

  • Kitizen
  • ****
  • Posts: 3697
Expect script to stop BTAgent in HG612 router
« on: December 30, 2012, 12:34:54 PM »

I have created a basic script using expect which is standard in Linux that will issue the necessary commands to remove the BTAgent processes after a reboot of the HG612. You may be able to modify it for other routers. Windows users will have to install the expect package for this to work. Save this as something memorable like BTAgent.expect and remember in Linux make sure you set the execute flag when you save the script.

Code: [Select]
#!/usr/bin/expect -f
# Expect script to supply root/admin password for remote ssh server
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
# Script will login to router and list running processes at which
# point the user is prompted to enter the PID for the BTAgent/ro/start
# entry shown in column 1-4 of the ps output. It will then issue the
# kill command for it followed by a killall for the btagent processes,
# and then re-issue the ps command before exiting.
#
# set Variables
set command [lrange $argv 0 0]
set timeout -1 
#
stty echo
send_user -- "Enter IP address of router: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set ipadd $expect_out(1,string)
#
spawn telnet $ipadd
match_max 100000

expect "*Login:"
send -- "admin\r"
expect "*?assword:"
send -- "admin\r"
expect "ATP>"
send -- "sh\r"
expect "# "
send -- "\r"
expect "*# "
send -- "ps\r"
expect "*# "
stty echo
send_user -- "Enter PID for BTAgent: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set pid $expect_out(1,string)
send -- "kill -TERM $pid\r"
expect "*# "
sleep 2
send -- "killall btagent\r"
expect "*# "
sleep 4
send -- "ps\r"
expect "*# "
send -- "exit\r"
expect "ATP>"
send -- "exit\r"
expect eof

The script will prompt for the correct IP address, login and issue the ps command to list the running processes on the router, it will then prompt for the correct PID value and then kill the relevant processes.

I decided to create this to save having to remember the correct commands on the rare occasions I needed to do this.

Stuart
Logged
ISP:Vodafone Router:Vodafone Wi-Fi hub FTTP

roseway

  • Administrator
  • Senior Kitizen
  • *
  • Posts: 43467
  • Penguins CAN fly
    • DSLstats
Re: Expect script to stop BTAgent in HG612 router
« Reply #1 on: December 30, 2012, 01:00:38 PM »

That's very neat, Stuart. I found that I had to install expect as it's not installed by default on Debian systems, but having done that, your script does what it says on the tin.
Logged
  Eric

broadstairs

  • Kitizen
  • ****
  • Posts: 3697
Re: Expect script to stop BTAgent in HG612 router
« Reply #2 on: December 30, 2012, 01:02:53 PM »

That's very neat, Stuart. I found that I had to install expect as it's not installed by default on Debian systems, but having done that, your script does what it says on the tin.

Good to know it works elsewhere, expect was a default install on my Fedora system.

Stuart
Logged
ISP:Vodafone Router:Vodafone Wi-Fi hub FTTP
 

anything