Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Red Hat This forum is for the discussion of Red Hat Linux.


  Search this Thread
Old 10-01-2009, 08:08 PM   #1
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 617

Rep: Reputation: 142Reputation: 142
log errors in cron job

Hi, on my Centos 5.2 system I run a cron job every night which backs up files from disk to a usb stick. The job simply creates a directory on the usb stick and then copies the files from disk to this new directory.

If I am not around I don't expect any of the other guys here to be able to diagnose a problem so I would like to copy a red light/green light file into a particular directory for their reference. I will act from there.

I am currently using "cp" to copy the files. Is there an error condition I can attach to this? Would "rsync" be a better option? Any other options to report errors in cron jobs?
Old 10-01-2009, 08:39 PM   #2
LQ Newbie
Registered: Mar 2009
Posts: 2

Rep: Reputation: 1
cp .......
echo "woohoo!" > /my/file
echo "D'Oh!" > /my/file

Compliments of the Bisman LUG
Old 10-02-2009, 03:09 AM   #3
Senior Member
Registered: Sep 2009
Location: Srbobran, Serbia
Distribution: CentOS 5.5 i386 & x86_64
Posts: 1,118
Blog Entries: 1

Rep: Reputation: 129Reputation: 129
You can also use something like this to check if certain files exist:

if [ ! -f $TestFile ]; then
      echo "$TestFile : does not exists" # Change this to what response/action you want
      exit 1 # This line will exit the script with error code 1. You can remove it if you want to continue running the script
elif [ ! -r $TestFile ]; then
      echo "$TestFile: can not read" # Change this to what response/action you want
      exit 2 # This line will exit the script with error code 2. You can remove it if you want to continue running the script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keep getting errors when running cron job that works in normal terminal. Techno Guy Linux - Newbie 6 05-31-2009 06:48 PM
Cron job won't redirect to log file holunde Linux - Software 3 06-28-2007 02:05 PM
Errors when running Perl script in a cron job meshach Slackware 2 06-20-2006 09:10 PM
log cron job to capture errors if there are ashley75 Linux - General 1 05-21-2004 10:34 AM
cron job errors existo Slackware 4 01-23-2004 02:40 PM

All times are GMT -5. The time now is 08:31 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration