Sample Header Ad - 728x90

How can I run a script when internet connection is about to get lost?

4 votes
2 answers
2074 views
I use wvdial (PPP dialer) with a SIM card modem and sometimes this connection is reset by server side. I would like to run a script which greps ifconfig to get a volume of data downloaded and stores it somewhere. Obviously it has to be done when connection is still alive, otherwise I get nothing, or a few seconds later a value for fresh connection, because wvdial is configured to immediately reconnect when connection is lost. Any idea? **Edit:** Of course I can grep output of ifconfig every second or two, but this is horrible workaround not even worth considering. The best scenario I can imagine is to somehow capture the signal which instructs ifconfig to "reset the counting" => suspend signal for a moment => run my script => unlock the signal. But maybe there are other possibilities which I'm not aware of like for example configure ifconfig itself to dump the previous result to a file if given interface disappears. Another option is to take output not from ifconfig by elsewhere. BTW, what is the input source for ifconfig?
Asked by WeSenseASoulInSearchOfAnswers (567 rep)
Oct 1, 2014, 10:21 PM
Last activity: Sep 26, 2016, 10:17 PM