Script after forced DSL disconnection
Is there a simple way to tag a script to a forced DSL disconnection?
Background: I have a customer with a household DSL line that disconnects every 24 hours, which is what one expects. His telco does not allow to enforce own timings for re-registration such that after the disconnection it may take a couple (and more) minutes before his pbx can be reached again from the outside. Unfortunately, this is a business, where this is a more crititical issue than at home.
The idea is to enforce a complete fresh registration when the public IP of the router changes.
I've seen the php code which generates the status pages for the interfaces, so I could get access to the vars I need and wrap the script by a cron job that runs maybe every 2 minutes and triggers the new registration. But maybe there is a more straightforward method.
If your script can run often without causing a problem you can probably run it from a shellcmd by choosing the afterfilterchangeshellcmd type. Since when the WAN comes back up it will trigger a filter reload I expect it to also trigger a shellcmd of that type.
There is a shellcmd package to make managing shellcmds easier.
If not then you can probably add it to /etc/rc.newwanip but it's always better to work just in the config if you can to avoid your changes being overwritten.
jsphgttgns last edited by jsphgttgns
Thank you, /etc/rc.newwanip was a good tip.
I am aware of shellcmd, but when the IP changes, the router won't reboot. I have already the cron package installed, where I have a couple of entries for my own housekeeping (like cleaning up Asterisk log files, cdr data, some special backups, etc).
Currently, I am just merely observing with the following script to capture new ips:
#!/bin/sh FILE=/tmp/wan-ip.txt LOG=/var/log/wan-ip.log IP=`/sbin/ifconfig pppoe0 | /usr/bin/grep inet\ | /usr/bin/cut -d\ -f2` [ -e $FILE ] || echo "0.0.0.0" >$FILE OLDIP=`cat $FILE` if [ "$IP" != "$OLDIP" ]; then echo $IP >$FILE echo `/bin/date +"[%F %T] $IP"` >>$LOG # enforce a fresh registration with the telco's sip proxy fi
Later I'll call a script that will do the right things, but the Asterisk details are not so interesting here. Essentially, I'll either enforce a fresh registration for all lines and trunks, or I restart the entire Asterisk server. This may be the only way, if the DSL connection gets reconnected with a new IP during business hours and existing sessions get interrupted. Asterisk itself tries to keep the old connections alive and protests with a lot of error messages. Hence the restart to forget the old states.
/etc/rc.newwanip looks more straightforward with the risk that things get broken when the customer updates his box, but there are ways to cope with that.
In either case, I think I'll call a script that calls a background task to detach things as much as possible from the GUI. If things hang (like bold calls to nmap), it won't at least affect the GUI...
The shellcmd type
afterfilterchangeshellcmdruns at every filter reload not just at boot so would likely work for you here.
@stephenw10 Cool, I wasn't aware of that option. Basically, I'll call a script that checks some parameters and then decides whether Asterisk needs attention in the background. This thing even gets saved with the configuration, except my scripts, but that's not a problem.
As a side effect I'd very likely can also catch interruptions for static IP WAN connections, .
If you use the Filer package you can have the script added to the config file so it's all backed up and can be restored in one shot should you need to.
@stephenw10 Works like a charm!