The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error in file writing in crontab capri_drm Shell Programming and Scripting 2 10-02-2009 03:26 PM
Check if 2 files are identical byte-to-byte? krishmaths Shell Programming and Scripting 4 09-04-2008 01:37 AM
Run perl file in Crontab error. raccsdl Shell Programming and Scripting 2 11-13-2007 07:07 AM
Crontab error Cannot execute binary file. raccsdl Shell Programming and Scripting 5 11-13-2007 06:22 AM
Error while creating .tar file using script Rakesh Bhat Shell Programming and Scripting 1 12-30-2005 01:40 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
DSDexter DSDexter is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 4
Crontab Error - creating zero byte log file

Hi,

I am trying to run a shell script using the crontab scheduler, and I am redirecting the log of the script output to some temp log file using the following command.

Code:
sh somescript.sh 1> /location/somefile.log
Evrytime the cronjob triggers this script, It creates a zero byte file in the location specified. I also tried with

Code:
sh somescript.sh > /location/somefile.log
But no luck. If I run a simple command like

Code:
rm -rf <somefile>
then this command is running sucessfully by cron. But why is it not creating the log of the script that has been run? Any help will be higly appreciated.

Last edited by pludi; 4 Weeks Ago at 07:55 AM.. Reason: code tags please...
  #2 (permalink)  
Old 4 Weeks Ago
cero cero is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 56
It would help if you post the entry in your crontab that is not working. Do you see any errors in the system-logfile?
  #3 (permalink)  
Old 4 Weeks Ago
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,839
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 13:56 ---------- Previous update was at 13:55 ----------

Unless your script resides in /root, cron won't find it. Put it into the crontab using the absolute path and see if it works.
  #4 (permalink)  
Old 4 Weeks Ago
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 438
You should use absolute path, unless you have the PATH variable defined.

We have it specified in lot of places such as
ping from cron
  #5 (permalink)  
Old 4 Weeks Ago
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,163
1) In most unixes the errors will be in root mail .
2) As suggested above, refer to the script name by absolute path unless the script happens to be in the limited default path available in cron.
3) There may also be need to set PATH in the script or refer to commands by absolute path,
4) You don't need the "sh " in front of the command. cron defaults to "sh".
5) If you want to capture all output from the script you will need to redirect the error channel too.

Suggested outline for the command field in the crontab line:

Code:
/absolute_path_to_script/somescript.sh 2>&1> /location/somefile.log
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0