LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

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

Rep: Reputation: 40
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
dm24047
LQ Newbie
 
Registered: Mar 2009
Posts: 2

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

Compliments of the Bisman LUG
 
Old 10-02-2009, 03:09 AM   #3
DrLove73
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:

Code:
TestFile=/my/file
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
fi
 
  


Reply


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 09:56 PM.

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