network auto (re)connect script
Posted: Sun 23 Jan 2011, 21:37
this code is part of a larger daemon that handles several things. I wrote it because I got frustrated with manually reconnecting via the gui every time something caused a failure of my wireless connection. It also extends the amount of time spent on the internet before the battery runs out by saving me from taking time to realize I'm disconnected then reconnect manually.
The [ -e /tmp/network.off ] was behaving oddly using both that and [ ! -e /tmp/network.off ]. The pidof firefox-bin && NETDC="NNff" saves battery power. I will change that at some point to look at network activity and disconnect when it falls to the level of "noise" (ARP, etc...) for a certain length of time.
Have fun with this and hope it helps someone else.
Edit: I should have mentioned this is on Lucid-Puppy 5.11
Code: Select all
netcheck() {
NETERR="Oops"; NETDC="CONN"; touch /tmp/network.nslo
# if [ -e /tmp/network.off ]; then
nice -n 2 nslookup www.google.com >> /tmp/network.nslo &
nice -n 2 nslookup www.yahoo.com >> /tmp/network.nslo &
nice -n 2 nslookup www.facebook.com >> /tmp/network.nslo &
# fi
sleep 5
cat /tmp/network.nslo | grep -ve "0.0.0.0" | grep -E "[0-9]+" && NETERR="muchOK"
echo -n "$NETERR ------ "
rm /tmp/network.nslo
[ -e /tmp/network.disconnect ] && NETDC="NNDC"
pidof firefox-bin && NETDC="NNff"
if [ "$NETERR" == "Oops" ] && [ "$NETDC" != "NNDC" ]; then
L_TITLE_S="Network"; L_MESSAGE_S="XXXXXX Network DisConnected XXXXXXX"; L_BG_S="red"; sleep 1
gxmessage -center -geometry 250x50 -timeout 2 -bg "$L_BG_S" -buttons "" -title "$L_TITLE_S" "$L_MESSAGE_S"
pidof rc.network || /etc/rc.d/rc.network stop
sleep 5
pidof rc.network || /etc/rc.d/rc.network start | tee /tmp/network.rc; sleep 1
grep -e Success /tmp/network.rc > /dev/null && NETERR="CONOK"
rm /tmp/network.rc
if [ "$NETERR" == "CONOK" ]; then
L_MESSAGE_S=" ++ Network Connected ++"; L_BG_S="green"; sleep 1;
gxmessage -center -geometry 250x50 -timeout 1 -bg "$L_BG_S" -buttons "" -title "$L_TITLE_S" "$L_MESSAGE_S"
rm /tmp/network.off
fi
fi
if [ "$NETERR" != "Oops" ] && [ "$NETDC" == "NNDC" ]; then
L_TITLE_S="Network"; L_MESSAGE_S="XXXXXX DisConnectIng Network XXXXXXX"; L_BG_S="yellow"; sleep 1
gxmessage -center -geometry 250x50 -timeout 5 -bg "$L_BG_S" -buttons "" -title "$L_TITLE_S" "$L_MESSAGE_S" &
sleep 1; /etc/rc.d/rc.network stop
touch /tmp/network.off
fi
}
Have fun with this and hope it helps someone else.
Edit: I should have mentioned this is on Lucid-Puppy 5.11