[ntp:questions] Local clock question with dialup connection

Nigel Henry cave.dnb at tiscali.fr
Mon Apr 23 23:35:27 UTC 2007


On Monday 23 April 2007 22:20, Steve Kostecke wrote:
> On 2007-04-23, Nigel Henry <cave.dnb at tiscali.fr> wrote:
> > The script needs to ping some server on the Internet. If it receives no
> > response, and exits with a code 1, it will then sleep for 60 secs, then
> > run the ping again, and so on. When an Internet connection is eventually
> > established, and that is if I understand this correctly, ping will then
> > exit with a code 0.
> >
> > Once a code 0 is received, showing the host to be alive, no further pings
> > should be sent, and the script at /usr/local/bin/ntp-restart will be run.
>
> Here's one way to do this. Handling situations such as when this script
> does not exit or more than one copy of this script is started are left
> as an excercise...
>
> #!/bin/sh
>
> # The hostname or IP address of the host that you want to ping.
> TARGET=
>
> while [ 1 ]
> do
>   /bin/ping -c 4 $TARGET 2>/dev/null >/dev/null && break
>   /bin/sleep 60
> done
>
> /usr/local/bin/ntp-restart

Thanks Steve. That's working like magic. I tried it on the CLI, and changed 
ntp-restart for a .wav file. Cut the Internet connection, ran the the script, 
and a few minutes later remade the Internet connection, and some seconds 
later the .wav played. Job done.

if you have the time, could you explain how the script works. There's hardly 
anything to it, but it does the job.

Many many thanks.

Nigel.

btw. I'm not pinging timeservers with this. My son set up a freebie webserver 
a couple of years ago for me, which I've never used, so I'm pinging that.



More information about the questions mailing list