PDA

View Full Version : script for keeping internet connection alive


ali baba
12-09-2002, 04:26 AM
if i type this into the terminal:
ping -i 300 www.versiontracker.com
then my internet connection stays alive

my question is:
how do i turn this into a script i can doubleclick in the dock?
or is there some other better way that doesn't take dockspace?
do i use applescript?

also i have searched the net and the apple knowlegdebase
and i can't quite figure out what a shell-script is..
can someone please give a brief description of what it is?

tia, ali b.

at_sym
12-09-2002, 05:04 PM
A shell script is just a small program that's written to be interpreted by the shell, which is the part of the operating system that accepts command-line input from the terminal. On Mac OS X, your shell is tcsh, but other shells include bash, csh, and zsh.

Here's a basic tutorial (http://vertigo.hsrl.rutgers.edu/ug/shell_help.html) that shows some examples of shell scripting (for sh, the Bourne shell).

You could make your ping line into an AppleScript using the built-in "do shell script" function (do shell script "/sbin/ping -i 300 www.versiontracker.com"). But if you don't want to take up any space in the Dock, you could use cron to ping a site or have curl make a connection every few minutes or something.

Cronnix (http://www.versiontracker.com/redir.fcgi/kind=0&db=mac&id=9478) adds a nice UI to cron and includes info on how to write cron jobs.

One thing, though... you may want to check with your ISP before doing this. Some of them (including a former employer of mine) get very squirrelly about people using keep-alive apps.

ali baba
12-09-2002, 06:36 PM
thanks for the clear description and links
i think i'll go with the applescript
but i have some questions

1) when i put
do shell script...r.com"
into the applescript editor window it runs but how do i make the app quit?

2) i am not sure but it seems to work without "/sbin/"
is the complete path necessary?

ali

at_sym
12-09-2002, 07:07 PM
Hi ali--

1) Save the script as an application. Be sure that "Never show startup screen" is checked. When you double-click it, it will open and run. If you want it to open and keep running in the background, check the "Stay open" box.

2) If it works without the /sbin/, you should be able to leave it out. I had to add it to get the script to work on 10.1.5. (IIRC, AppleScript uses (used?) zsh for the do shell script function, and zsh complained that it couldn't find ping when I left out the path. I don't have a 10.2 computer handy, so this may no longer be the case.)

Good luck!

ali baba
12-09-2002, 07:26 PM
hi at_sym,

i had done all that
saved as app and checked the never show checkbox
but once i start this app
only way to quit is force quitting..
there has to be a more elegant way
or something i'm missing?

thanks for the answers, ali

at_sym
12-10-2002, 01:36 AM
Unless you use the -c flag, ping will just keep going until you stop it. As far as AppleScript is concerned, the command isn't finished, so it requires you to force quit.

If you want to have something that launches, pings a site, and then closes, you can save ping -c 1 www.versiontracker.com as an AppleScript, then use cron to launch the script every five minutes. Or, even better, you could just use cron to schedule a single ping every five minutes. That way, you won't get the bouncing icon in the Dock.

ali baba
12-10-2002, 03:32 AM
hmm there's something strange..

i have installed cronnix as you advised

but when i input
ping -c 1 www.versiontracker.com
in the command-field (and ping every 5 minutes)
then the connections drops

but when input
ping -i 300 www.versiontracker.com
into the terminal, it works, no drop

so to check if cronnix worked
i had input a curl-command into the command-field
strangely this does keep the connection alive
but i'd rather opt for the "cleaner" ping-command

any ideas as to why a ping-command in cronnix
doesn't work as opposed to the same in the terminal?

tia for your answers and patience, ali

at_sym
12-10-2002, 03:33 PM
Hrm. That is really weird. I just tried setting this up using Cronnix, and the ping's not working for me, either. But curl and whois work fine. So it's not just you, but I'm not sure why it's not working.

Unfortunately, I don't know a whole lot about what is and isn't permitted in a crontab. Maybe a Unix guru like Sao or MervTormel could shine a light on what's happening.

Sorry I couldn't be of more help! :(

mervTormel
12-10-2002, 03:55 PM
crontab entry:

* * * * * root /sbin/ping -c1 mindspring.com | tee /tmp/foo$$


works fine for me. always use the full path to the command.


but this thread pains me. what are we trying to solve? keep your connection alive. but it's gotten muddled with teaching shell scripting, and now cron.

suggestion: config your email app to check mail every five minutes. that will keep your connection alive while you go read some unix shell scripting tutorials.

ali baba
12-10-2002, 04:07 PM
Sorry I couldn't be of more help! :(

hey you've been of great help! :)
i've learned a lot trying the suggestions
let's hope the guri (?) notice this thread

cheers, ali

ali baba
12-10-2002, 04:42 PM
Originally posted by mervTormel
crontab entry:

* * * * * root /sbin/ping -c1 mindspring.com | tee /tmp/foo$$

works fine for me. always use the full path to the command.

but this thread pains me. what are we trying to solve? keep your connection alive. but it's gotten muddled with teaching shell scripting, and now cron.

suggestion: config your email app to check mail every five minutes. that will keep your connection alive while you go read some unix shell scripting tutorials.

ah yes faster than my prev reply
thanks for the solution!

i knew how to keep a conn alive
that was not the issue
we were/i was looking for an elegant solution w/o mail
thanks for providing the correct string
but i'm glad it got muddled by shell script and cron
you wanna go from a to b
but end up taking a zig-zag road
learning things you had not forseen
ever noticed life is like that?

cheers, ali

gatorparrots
12-17-2002, 01:58 AM
Some ISPs will block such regular ping efforts to maintain a keepalive connection. You may be better off with a series of crontab tasks that alternate pulling the headers from various web pages:
*/2 * * * * curl -I www.apple.com
*/3 * * * * curl -I www.macupdate.com
*/5 * * * * curl -I www.versiontracker.com/macosx/
*/7 * * * * curl -I www.maccentral.com

eightreal
09-13-2008, 01:49 PM
does anyone know the best way to have the terminal ping diferent sites every 5 min to keep the connection alive. Thanks