ping inside of crontab fails to produce output

DominikHoffmann

Registered
Here is my root's crontab (see my other post on why I have that stuff in there):
Code:
*       *       *       *       *       echo `date` -- `ping -c 1 xx.xx.xx.34 | sed -n -e 's/.*0\%.*/up/' -e 's/.*100\%.*/down/' -e "/up/p" -e "/down/p"` >> /var/log/uptime.log
*       *       *       *       *       ping xx.xx.xx.34 >> /var/log/ping.log
Interestingly, the first line fails to produce the desired output, and the second produces none at all. What am I missing?

Dominik Hoffmann
 
Hi,

Maybe you should add the full path of the 'ping' utility to the ping calls.

Secondly, you should call ping specifying the total number of packets to be sent, to prevent the job from not ending.

And thirdly, it would be best for you to encapsulate all this work on a single shell file and call the shell file only from cron.


Dani
 
Thank you very much, Dani. Using the full pathnames works. I guess, cron knows /bin/, but not /sbin/ or /usr/bin/.

I also appreciate the tip about using a shell script.

Dominik Hoffmann
 
dani++ said:
And thirdly, it would be best for you to encapsulate all this work on a single shell file and call the shell file only from cron.
Is there a canonical location for placing this file? I am loathe to put it into any of /bin/, /sbin/ or /usr/bin/. In other words, is there a bin directory for mods that go beyond the stock install, just like I would put StartupItems into /Library/, rather than /System/Library/.

Dominik
 
You could put it anywhere. I actually created the folder /Library/CronJobs just for 'em on my systems. I put a few maintenance scripts I created there. So long as you put the full path to them in the crontab, it doesn't matter where they are.
 
Back
Top