View previous topic :: View next topic |
Author |
Message |
w0kKiD n00b
Joined: 17 Oct 2005 Posts: 59 Location: Netherlands
|
Posted: Thu Jul 05, 2007 9:29 pm Post subject: help writing ping script to stop wireless disconnecting |
|
|
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 |
|
|
madchaz l33t
Joined: 01 Jul 2003 Posts: 995 Location: Quebec, Canada
|
Posted: Fri Jul 06, 2007 12:35 am Post subject: |
|
|
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 |
|
|
w0kKiD n00b
Joined: 17 Oct 2005 Posts: 59 Location: Netherlands
|
Posted: Fri Jul 06, 2007 1:36 pm Post subject: |
|
|
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 |
|
|
martin20450 Tux's lil' helper
Joined: 30 Sep 2005 Posts: 91
|
Posted: Fri Jul 06, 2007 3:11 pm Post subject: |
|
|
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 |
|
|
w0kKiD n00b
Joined: 17 Oct 2005 Posts: 59 Location: Netherlands
|
Posted: Sun Jul 08, 2007 2:13 pm Post subject: |
|
|
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 |
|
|
martin20450 Tux's lil' helper
Joined: 30 Sep 2005 Posts: 91
|
Posted: Tue Jul 10, 2007 12:49 pm Post subject: |
|
|
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 |
|
|
schally Apprentice
Joined: 13 May 2004 Posts: 207
|
Posted: Tue Jul 10, 2007 12:55 pm Post subject: |
|
|
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 |
|
|
w0kKiD n00b
Joined: 17 Oct 2005 Posts: 59 Location: Netherlands
|
Posted: Thu Jul 19, 2007 10:08 pm Post subject: |
|
|
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 |
|
|
martin20450 Tux's lil' helper
Joined: 30 Sep 2005 Posts: 91
|
Posted: Thu Jul 19, 2007 10:16 pm Post subject: |
|
|
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 |
|
|
schally Apprentice
Joined: 13 May 2004 Posts: 207
|
Posted: Fri Jul 20, 2007 6:55 am Post subject: |
|
|
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 |
|
|
w0kKiD n00b
Joined: 17 Oct 2005 Posts: 59 Location: Netherlands
|
Posted: Sat Jul 21, 2007 1:41 am Post subject: |
|
|
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 |
|
|
schally Apprentice
Joined: 13 May 2004 Posts: 207
|
Posted: Tue Jul 24, 2007 10:35 am Post subject: |
|
|
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 |
|
|
w0kKiD n00b
Joined: 17 Oct 2005 Posts: 59 Location: Netherlands
|
Posted: Tue Jul 24, 2007 11:15 pm Post subject: |
|
|
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 |
|
|
schally Apprentice
Joined: 13 May 2004 Posts: 207
|
Posted: Wed Jul 25, 2007 7:32 am Post subject: |
|
|
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 |
|
|
w0kKiD n00b
Joined: 17 Oct 2005 Posts: 59 Location: Netherlands
|
Posted: Wed Jul 25, 2007 3:59 pm Post subject: |
|
|
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 |
|
|
gerardo Apprentice
Joined: 05 Feb 2004 Posts: 228 Location: Belgium
|
Posted: Tue Aug 14, 2007 10:51 pm Post subject: |
|
|
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 |
|
|
|