Cron + Script = No Output? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Cron + Script = No Output?

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-14-2004
jmf77 jmf77 is offline
Registered User
 
Join Date: Dec 2004
Last Activity: 21 December 2004, 9:43 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 12-14-2004
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 16 September 2014, 1:08 PM EDT
Location: Ashburn, Virginia
Posts: 9,925
Thanks: 60
Thanked 434 Times in 259 Posts
Maybe your ping writes to stderr rather than stdout. Try:
ping -c 1 192.168.1.20 > ~/onlinestatus.txt 2>&1
Sponsored Links
    #3  
Old 12-15-2004
jmf77 jmf77 is offline
Registered User
 
Join Date: Dec 2004
Last Activity: 21 December 2004, 9:43 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 12-21-2004
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
 
Join Date: Aug 2001
Last Activity: 18 April 2013, 3:03 PM EDT
Location: San Antonio, TX,
Posts: 1,070
Thanks: 0
Thanked 4 Times in 4 Posts
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  
Old 12-21-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 24 Times in 23 Posts
Quote:
Originally posted by jmf77
I get some kind of "Resource not available" error written to the file now. What does that translate to?
What's the exact output left in the file?

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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 01:28 PM.