# ping inside of crontab fails to produce output



## DominikHoffmann (Jan 17, 2005)

Here is my root's crontab (see my other post on why I have that stuff in there):

```
*       *       *       *       *       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


----------



## dani++ (Jan 18, 2005)

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


----------



## DominikHoffmann (Jan 18, 2005)

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


----------



## DominikHoffmann (Jan 18, 2005)

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


----------



## Darkshadow (Jan 19, 2005)

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.


----------

