Help with script, shutdown if no ping responce

Thanks, il try the code as it is as root first. Il post the result hang on.

Ignore, mistake.

One problem, the script runs forever. Can you please edit it so it only runs for say 10secs constantly when it is executed.

Which one are you running?

Post the output of the script...

And post your actual script.

What does "/usr/sbin/ping ip-address" do, does it just say "host is alive" or does it run forever?

Right, i think the modem was just rejecting the ping if i pinged it constantly like the script was doing.

if i type ping 192.168.100.1 into terminal i get a host is alive.

Im running the second script you gave to me

I think i have it working now, setup with the cronjob and everything. Could i just ask how long this script is set to run for? because if it runs constantly forever my modem will start to reject the pings. I have told cron to run the script every min. But what i would like it to do is run for 10 secs only each time.

if i ping thru usr/sbin/ping 192.168.100.1 i get one responce.

It should be just pinging it three times in the "for" loop, not continually.

Now if i unplug the modem the script doesnt seem to run, or do anything.

The script doesnt seem to work unless i run it manually, can you please tell me what to put in the cronjob file to make the script run every min.

  1. You normally have to fully path the script in the crontab file.

  2. you may need to fully path the shutdown program in the script as well.

I have the full path to the script in the crontab file, hmm the full path to the shutdown program, could i ask what this would be with solaris 10?

just to make sure

in the crontab to run every 1 min i should have?

1 * * * * etc/ping > ect/pinglog

is this correct

I thought you would have something like....

1 * * * * /path/to/my/script/to/do/this/pinging.sh >/var/log/lastpingthing.log

hmm still no luck, it works fine aslong as i run it manually, putting it in that file doesnt seem to make any diffrence atall.

Do you know how to add a crontab entry?

As this needs to be run by root, do the following as root....

  1. in some temporarty directory...

  2. crontab -l >crontab

  3. edit the crontab file

  4. crontab crontab

  5. crontab -l

Oh, i thought you just had to use crontab -e and add it from there.

Yeah so when i edited it, and use crontab -l it shows up. i restart the machine and nothing.

Double checked everything, this script doesnt want to run from cron :frowning:

Change the first line to

#!/bin/sh -x

and capture both stdout *and* stderr, something like...

1,6,11,16,21,26,31,36,41,46,51,56 * * * * fully-qualified-script-path >/var/log/mystdout 2>/var/log/mystderr

Just to muddy the waters some more :stuck_out_tongue: You should really consider pinging more than one thing before deciding to shutdown. Otherwise a router restart could shut down your server. Does your UPS have a network or serial port on it? It might be capable of sending a warning to the server directly in the event of a failure.

Yeah it has a serial port but i cant get it to work with solaris, thats why i had this idea.

The original idea was to have more then one address to ping but i decided that becuase the machine is strictly a file server only it wouldnt really matter if the router cut it out every couple of weeeks.

Still cant get it to work.

Right, so i have got it to work, only by actually inputting every time i want it to run into the crontab, but now the next problem is that it wont do a clean shutdown :confused: