We had this problem with one of our Internet links which was an ADSL/PPPoE connection. Every now and then this Internet connection seems to be unstable and it affected Internet access through this line. One solution we came across is resetting the ADSL connection either by pulling the cable off or shut/unshut the interface. Once the ADSL/PPPoE gets reconnected, Internet access becomes stable again.
While waiting for the service provider to fix the issue (if it gets fixed), we needed to every now and then reset the interface connecting the ADSL/PPPoE line. This can be during after office hours (i.e. 12MN) but should be automated (I can't be doing this manually) Here comes my Python Network Script (netscript) discussed here in my post along with cron. Below are my steps in automating this task.
First we create the command file (interface_reset.txt) which will shutdown and enable the network interface.
While waiting for the service provider to fix the issue (if it gets fixed), we needed to every now and then reset the interface connecting the ADSL/PPPoE line. This can be during after office hours (i.e. 12MN) but should be automated (I can't be doing this manually) Here comes my Python Network Script (netscript) discussed here in my post along with cron. Below are my steps in automating this task.
First we create the command file (interface_reset.txt) which will shutdown and enable the network interface.
#!/bin/bash
/opt/scripts/netscript.py -t 192.168.1.1 -u netscript -p password \
-c /opt/scripts/interface_reset.txt -v
Note that this command file will wait for 60 seconds before renabling the interface.
Then we create the bash script (cisco_adsl_reset.sh) that will invoke the python script along with the command file.
Then we create the bash script (cisco_adsl_reset.sh) that will invoke the python script along with the command file.
# Enable interface
configure terminal
interface Gi1/0/1
description # Automated reset Internet/ADSL/PPPoE
shutdown
!wait
no shutdown
end
This script invokes the python script with the user "netscript" with level 15 privilege) on the target IP address and the command file "interface_reset.txt". The parameter -v is for verbose output useful for debugging. We need to ensure the script can be executed
chmod 755 cisco_adsl_reset.sh
You need to test this script by running the bash script on the command line.
# ./cisco_adsl_reset.sh
-----------------------
Input parameters
Target host : 192.168.1.1
Username : netscript
Password : xxxxxx
Command file : /opt/scripts/interface_reset.txt
Verbose : True
-----------------------
SSH connection established to 192.168.1.1
Comments: # Enable interface
Command: configure terminal
Command: interface Gi1/0/1
Command: description # Automated enabled Internet/ADLS/PPPoE
Command: shutdown
Command: !wait
Command: no shutdown
Command: end
Sleeping in 1 seconds
CISCO_TEST_ROUTER#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
CISCO_TEST_ROUTER(config)#interface Gi1/0/1
CISCO_TEST_ROUTER(config-if)#$utomated enabled Internet/ADLS/PPPoE
CISCO_TEST_ROUTER(config-if)# shutdown
CISCO_TEST_ROUTER(config-if)# !wait
CISCO_TEST_ROUTER(config-if)# no shutdown
CISCO_TEST_ROUTER(config-if)#end
CISCO_TEST_ROUTER0#
Closing SSH connection
#
We can confirm the script is working as intended as it accessed the device and shut/enabled the target interface. Now we need to schedule this script to run every midnight via the cron. We add this line in the /etc/crontab.
This script has also been tested with HP Comware network devices as long as we use accounts with admin privilege.
# Network Scripts (Restart ADSL Internet everyday midnight)
0 0 * * * root /opt/scripts/cisco_adsl_reset.sh > /dev/null