DrJohnZoidberg
Honorary Master
I am always Googling for bash script ideas and with recent problems with our adsl at the office I decided to make a little bash script that will notify me via email when the 3G backup kicks in. Thought I would just share with you in case somebody may need something similar in the future. Our modem has no features for notifications, so had to write one myself.
The script is very basic and just checks connection based on ip, our main adsl line is an IS based account IP starting with 19 and the 3g backup is 8ta which IP starts with 41. You could build a lot more around this, here is the basic script:
checkconnection.sh:
connection-3g.txt (sendmail file):
Just pop this in to a cronjob and run every 5 minutes or so.
Still a bit of work to do to refine it, maybe you guys can throw some ideas my way. One thing I have to do is also switch the postfix smtp relay from the IS smtp server to saix when 3g kicks in, this is pretty basic though.
Happy scripting
The script is very basic and just checks connection based on ip, our main adsl line is an IS based account IP starting with 19 and the 3g backup is 8ta which IP starts with 41. You could build a lot more around this, here is the basic script:
checkconnection.sh:
Code:
#!/bin/bash
ip="`curl http://automation.whatismyip.com/n09230945.asp`"
ipfirst="${ip:0:2}"
ipadsl="19"
ip3g="41"
if [ "$ipfirst" == "$ipadsl" ];
then
echo "You are connected with ADSL"
rm -rf connection-fault
else
if [ "$ipfirst" == "$ip3g" ];
then
if [ -f /root/connection-fault ];
then
echo "You are connected with 3G."
else
touch connection-fault
/usr/sbin/sendmail -t < /root/connection-3g.txt
echo "You are connected with 3G and I have sent you a mail."
fi
else
echo "Could not determine the status of your connection."
fi
fi
connection-3g.txt (sendmail file):
Code:
subject: Internet connection at 021xxxxxxxx has failed
from: admin@linuxbackup
to: yourworkemail@address
cc: yourprivateemail@address
Your connection at 021 xxx xxxx has failed and been switched over to the backup 3G connection.
Just pop this in to a cronjob and run every 5 minutes or so.
Still a bit of work to do to refine it, maybe you guys can throw some ideas my way. One thing I have to do is also switch the postfix smtp relay from the IS smtp server to saix when 3g kicks in, this is pretty basic though.
Happy scripting