Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
help writing ping script to stop wireless disconnecting
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
w0kKiD
n00b
n00b


Joined: 17 Oct 2005
Posts: 59
Location: Netherlands

PostPosted: Thu Jul 05, 2007 9:29 pm    Post subject: help writing ping script to stop wireless disconnecting Reply with quote

OK I've got wireless internet working nicely on my laptop now through a PCMCIA card sporting a rt2500 chip. I use the legacy stable rt2500 drivers, not the rt2x00 ones. However, if the network is left unused for roughly 90 to 120 seconds (1.5 to 2 minutes) the card will disconnect. iwconfig will still report it as connected to my router and the net.ra0 service will still be running, but the two little lights on the card will be off and there will be no usable network connection ie cant even ping the router.
I've discovered that a way to solve this is either to just run "/etc/init.d/net.ra0 restart" when I need the network again, or to constantly keep a ping on google.com running in a terminal with a 90 second interval, just so that it doesn't stress the network too much. What I'd like to do is create a script which I could run to run that ping in the background ie no terminal open, and on demand ie I don't want to run it as soon as net.ra0 starts at boot because I might be travelling and needing to reconfigure the network or I might want to be working without the network and the last thing I need is a failed ping running all the time.
I'm a bit of a n00b at shell scripting, and I had a crack at writing a simple loop script myself, but it all pretty much failed. If it helps, I run Gnome 2.16 so the idea is that I have a little launcher on the Gnome Panel which I can click on to get the ping running.
Thanks in advance for any help in this project!!

PS I guess that another solution would be to do something to simply configure the card to not disconnect all the time or something like that. Also, in case you're wondering what my problem is with running "/etc/init.d/net.ra0 restart", which seems simple enough, it's that I sometimes have a little trouble connecting to the right AP, so I'd rather not have to go through the process of manually configuring an ESSID to connect to every time I want to restart the connection and instead simply keep the connection alive once it's there.
Back to top
View user's profile Send private message
madchaz
l33t
l33t


Joined: 01 Jul 2003
Posts: 995
Location: Quebec, Canada

PostPosted: Fri Jul 06, 2007 12:35 am    Post subject: Reply with quote

make a small sh that does one ping, then quits. Put that in the cron to run every minute.
_________________
Someone asked me once if I suffered from mental illness. I told him I enjoyed every second of it.
Back to top
View user's profile Send private message
w0kKiD
n00b
n00b


Joined: 17 Oct 2005
Posts: 59
Location: Netherlands

PostPosted: Fri Jul 06, 2007 1:36 pm    Post subject: Reply with quote

madchaz wrote:
make a small sh that does one ping, then quits. Put that in the cron to run every minute.

That wouldn't even require a script, "ping -c1 google.com" is enough. However, I've never really used cron before, although I do have vixie-cron installed as suggested in the handbook. How would I put it in to run every minute? Also, I don't want it running on startup, only when I request it, meaning I would also like to be able to stop it whenever I need to.
Back to top
View user's profile Send private message
martin20450
Tux's lil' helper
Tux's lil' helper


Joined: 30 Sep 2005
Posts: 91

PostPosted: Fri Jul 06, 2007 3:11 pm    Post subject: Reply with quote

Or simply
Code:
ping -i 90 router.ip.address > /dev/null &

That'll ping your router every 90 seconds putting the output into the bit bucket.
Back to top
View user's profile Send private message
w0kKiD
n00b
n00b


Joined: 17 Oct 2005
Posts: 59
Location: Netherlands

PostPosted: Sun Jul 08, 2007 2:13 pm    Post subject: Reply with quote

That's a nice solution! I forgot about the existence of /dev/null, it's pretty much exactly what I needed when I was trying to solve this on my own. Also, the & at the end means that the process is run in the background right? Does that mean I can then close the terminal where I issued the command and the ping will still be running?
Back to top
View user's profile Send private message
martin20450
Tux's lil' helper
Tux's lil' helper


Joined: 30 Sep 2005
Posts: 91

PostPosted: Tue Jul 10, 2007 12:49 pm    Post subject: Reply with quote

The & will indeed put it into the background, however closing the terminal will terminate the ping also, you could instead do nohup ping etc which will keep the program running even if the terminal is closed.
Back to top
View user's profile Send private message
schally
Apprentice
Apprentice


Joined: 13 May 2004
Posts: 207

PostPosted: Tue Jul 10, 2007 12:55 pm    Post subject: Reply with quote

I'd just write a little c-program,...


main()
{
while(1)
{
system("ping www.google.com");
sleep(90);
}
}
_________________
Our glory is not in never falling but in rising again every time we fall -Konfuzius

greetz
- schally
Back to top
View user's profile Send private message
w0kKiD
n00b
n00b


Joined: 17 Oct 2005
Posts: 59
Location: Netherlands

PostPosted: Thu Jul 19, 2007 10:08 pm    Post subject: Reply with quote

I'm sorry I left this thread hanging, but I haven't had access to the Internet for a little while now. I'm rather intrigued by the C script, being a complete newcomer to that language, but the way I see it that would create a little program which would fulfill my task exactly. However, as I said I haven't the slightest idea how C works, or how to compile the script you created, so I would very much appreciate a bit of help with that. For now, the nohup background ping seems to be a decent solution.
Back to top
View user's profile Send private message
martin20450
Tux's lil' helper
Tux's lil' helper


Joined: 30 Sep 2005
Posts: 91

PostPosted: Thu Jul 19, 2007 10:16 pm    Post subject: Reply with quote

Forget the C script, all it does is call the ping command which you can invoke anyway, see my previous message, I used that technique for years without any ill harm - simpler to use something that exists than to re-invent the wheel :)
Back to top
View user's profile Send private message
schally
Apprentice
Apprentice


Joined: 13 May 2004
Posts: 207

PostPosted: Fri Jul 20, 2007 6:55 am    Post subject: Reply with quote

martin20450 wrote:
Forget the C script, all it does is call the ping command which you can invoke anyway...


thought that was the question,...

martin20450 wrote:

I used that technique for years without any ill harm,...


oh sry didn't see that i've put some ill harm into the c-program,...

martin20450 wrote:

simpler to use something that exists than to re-invent the wheel :)


oh didn't know that I've re-invented something,... lulz
_________________
Our glory is not in never falling but in rising again every time we fall -Konfuzius

greetz
- schally
Back to top
View user's profile Send private message
w0kKiD
n00b
n00b


Joined: 17 Oct 2005
Posts: 59
Location: Netherlands

PostPosted: Sat Jul 21, 2007 1:41 am    Post subject: Reply with quote

I've found that running the following works nicely:
Code:

nohup ping -i90 google.com >> /dev/null &

It also works if I type that into a launcher in the GNOME Panel because I guess the nohup program acts as a good proxy kind of thing to keep the ping running completely in the background. Only thing is that the only way I can close it is through something like top or the Gnome system monitor, but that's no big deal. Still interested in compiling C programs though :)
Back to top
View user's profile Send private message
schally
Apprentice
Apprentice


Joined: 13 May 2004
Posts: 207

PostPosted: Tue Jul 24, 2007 10:35 am    Post subject: Reply with quote

Code:


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    while(1)
    {
           system("ping www.google.com");
           sleep(90000); //time to wait in milli-seconds
    }
    return(0);
}




just put that into a file called pingprog.c for example an call from the command line:

Code:

gcc -o pingprog pingprog.c


then you should be able to run it with:

Code:

pingprog or
./pingprog


that should be everything,... just don't know if it will put the output on the command line, but then there would be some hints to prevent it or some more to make it a zombie-process,...

if you got problems just post,...
_________________
Our glory is not in never falling but in rising again every time we fall -Konfuzius

greetz
- schally
Back to top
View user's profile Send private message
w0kKiD
n00b
n00b


Joined: 17 Oct 2005
Posts: 59
Location: Netherlands

PostPosted: Tue Jul 24, 2007 11:15 pm    Post subject: Reply with quote

The program compiled fine, but unfortunately I'm running into some connection issues at the moment:
https://forums.gentoo.org/viewtopic-t-572221.html
This means the ping isn't working, but the script is. Only thing is that it posts it output into the terminal, which I also then cannot close.
Back to top
View user's profile Send private message
schally
Apprentice
Apprentice


Joined: 13 May 2004
Posts: 207

PostPosted: Wed Jul 25, 2007 7:32 am    Post subject: Reply with quote

Code:

#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
#include <sys/types.h>

#define CHILD 0

int main(int argc, char **argv)
{
   pid_t pid;
    if((pid = fork()) != CHILD) exit(0);
    while(1){
      system("ping www.google.com");
      sleep(90000);      
   }
   return 0;
}


think that'll fix this program,... read your other problem but have no clue,...
_________________
Our glory is not in never falling but in rising again every time we fall -Konfuzius

greetz
- schally
Back to top
View user's profile Send private message
w0kKiD
n00b
n00b


Joined: 17 Oct 2005
Posts: 59
Location: Netherlands

PostPosted: Wed Jul 25, 2007 3:59 pm    Post subject: Reply with quote

Thanks for the new script, I'll give it a shot the next time I get a connection on my laptop and report back.
Back to top
View user's profile Send private message
gerardo
Apprentice
Apprentice


Joined: 05 Feb 2004
Posts: 228
Location: Belgium

PostPosted: Tue Aug 14, 2007 10:51 pm    Post subject: Reply with quote

Shouldn't it be enough to ping your wireless router instead of "overloading" the internet by pinging google.com ?

nohup ping -i90 192.168.1.1 >> /dev/null &
_________________
Windoze : Plug and Pay...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
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