|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Cron + Script = No Output?
I've got an *extremely* simple script I want to run every minute: Code:
#!/bin/sh ping -c 1 192.168.1.20 > ~/onlinestatus.txt So, the script is called "status", it's executable, and in the correct path, etc. In a terminal window (I'm using Mac OS X), I can type status, and it will create onlinestatus.txt with the ping output in it. Everything seems to be working fine. HOWEVER, when I put the command in my crontab as * * * * * status It doesn't work. Or, to be more precise, it creates an *empty* onlinestatus.txt file. I can use Cronnix (a GUI crontab editor) to force the command to run. When I do that, onlinestatus.txt *does* contain the ping output; it seems like it's only when cron runs it at the scheduled interval that the text file comes out empty. I'm *thoroughly* confused. If it didn't work *at all*, I could deal with it, but this behavior doesn't seem to make any sense. Any suggestions?
|
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Maybe your ping writes to stderr rather than stdout. Try:
ping -c 1 192.168.1.20 > ~/onlinestatus.txt 2>&1 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Well, adding 2>&1 actually put some output in the file, except it's not what I'd hoped. I get some kind of "Resource not available" error written to the file now. What does that translate to?
Thanks! |
|
#4
|
||||
|
||||
|
First way to test a script is to execute it on the command line...if that succeeds then you should be able to run it from cron...
sometimes you might need to add a line "set -x" to test and see where your error is. |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Quote:
If it's something along the lines of "Destination unreachable", or something along those lines it's not a problem with your script. Post the contents of the output file. Cheers ZB |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to run a script using cron job and send the output as attachment via e-mail using unix | vidhyaS | Shell Programming and Scripting | 8 | 06-09-2011 02:20 AM |
| cron a script and output to file named with date stamp | landog | Shell Programming and Scripting | 3 | 05-02-2011 09:20 AM |
| Cron task output is 0, script output is OK | scottm | Red Hat | 1 | 10-19-2010 08:47 PM |
| Script not running from cron it gives blank output | jagadish_gaddam | Shell Programming and Scripting | 1 | 03-25-2010 03:53 PM |
| Script that Redirect SSH output via cron | primp | Shell Programming and Scripting | 4 | 06-14-2008 02:46 PM |
|
|