Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 19 Apr 2014, 23:33
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
network auto (re)connect script
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [4 Posts]  
Author Message
Softwaregurl

Joined: 23 Jan 2011
Posts: 49
Location: a state of mind

PostPosted: Sun 23 Jan 2011, 17:37    Post subject:  network auto (re)connect script
Subject description: automaticly disconnect when not needed or reconnect to a wireless network when connection is lost
 

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.
Code:
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
}


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
Back to top
View user's profile Send private message 
jemimah


Joined: 26 Aug 2009
Posts: 4309
Location: Tampa, FL

PostPosted: Sun 23 Jan 2011, 21:45    Post subject:  

Hiya and welcome to the forums,

Perhaps you'd like to help me with the Frisbee network manager, which is not yet available for LuPu, but you can test it in Fluppy011.
http://murga-linux.com/puppy/viewtopic.php?t=56156

Frisbee is totally different architecturally from SNS and network wizard and I intend it to be a replacement once it's ready. It won't drop your connections because it uses wpa_supplicant and dhcpcd as background daemons that know when the connection is dropped and reconnect you automatically. (Wpa_supplicant can handle WEP and open connections too, which make most of the complexity of managing connections magically disappear,) In addition, wpa_supplicant can automatically handle roaming if one network disappears and another becomes available - or in the case that you suspended in one location and resumed in another.

Frisbee is intended to be userfriendly and behaves much more like the network managers found in other operating systems.
Back to top
View user's profile Send private message Visit poster's website 
Softwaregurl

Joined: 23 Jan 2011
Posts: 49
Location: a state of mind

PostPosted: Mon 24 Jan 2011, 19:09    Post subject:  

Thanks for the welcome jemimah.

I took a peek at the thread this morning. I'll download a copy and check it out when I have a chance.
Back to top
View user's profile Send private message 
tommy

Joined: 04 Oct 2005
Posts: 78
Location: Italy

PostPosted: Wed 02 Jan 2013, 09:18    Post subject:  

Let me say AN ENORMOUS THANK YOU to softwaregurl who provided this wonderful piece of bash script.

MY PROBLEM WAS:
I have a cheap dikom wifi dongle using zd1211rw module. It is very uneasy and it drops wifi connection every now and then (it can work rock solid for 1 hour to 9 hours, then it loses the access point association). This is very frustrating, especially when using Transmission bittorrent, as I leave it to run overnight or when I'm not at home.

MY SOLUTION:
I slightly modified softwaregurl's script to suit my network and my needs:

Code:

#!/bin/sh
while true
do

   NETERR="Oops"; NETDC="CONN"; touch /tmp/network.nslo
#   if [ -e /tmp/network.off ]; then
   ping -c 1 192.168.2.1 >> /tmp/network.nslo &
#   fi
sleep 40
      cat /tmp/network.nslo | grep -c "100% packet loss" | grep -E "[0]+" && NETERR="muchOK"
      cat /tmp/network.nslo | wc -c < /tmp/network.nslo | grep -c "46" | grep -E "[1]+" && NETERR="Oops"
      echo -n "$NETERR ------ "
      rm /tmp/network.nslo
 #  [ -e /tmp/network.disconnect ] && NETDC="NNDC"
 #  pidof seamonkey-bin && NETDC="NNff"
 #  if [ "$NETERR" == "Oops" ] && [ "$NETDC" != "NNDC" ]; then
    if [ "$NETERR" == "Oops" ]; 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 5
      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

done



Note:
-I am not a bash programmer so I know it can be improved/ it sucks
- note that I ping my router (192.168.2.1) , not the web (because sometimes my router drops ADSL connection so it isn't wifi fault).
- I had to add this line
Code:

cat /tmp/network.nslo | wc -c < /tmp/network.nslo | grep -c "46" | grep -E "[1]+" && NETERR="Oops"

because sometimes my usb dongle goes down and / or network becomes unreachable, so the file /tmp/network.nslo becomes a 46-bytes-long file like this:

PING 192.168.2.1 (192.168.2.1): 56 data bytes

and lacks the "100% packets loss" part.
-I commented out various things in softwaregurl's script such as the 'stay disconnected' lines at the end of his script. I always need to be connected!!
- ping interval is 40 seconds (sleep 40), I think it's ok to not clug my network with many packets. Change at your needs.
- this script output can be read in /tmp/xerrs.log
- I use it on Puppy Turbopup Extreme ( 4.1.2 puplet) so it should work on every puppy I know of. I have put it on /root/Startup foder so it runs at every reboot automatically.

@ jemimah: I don't have a modern Puppy, so I can't use frisbee. Also I DON'T WANT DHCP. Can frisbee connect with fixed IPs?

Any thoughts welcome.

Happy new Year!![/code]
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0581s ][ Queries: 11 (0.0032s) ][ GZIP on ]