LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   log errors in cron job (https://www.linuxquestions.org/questions/red-hat-31/log-errors-in-cron-job-759102/)

timl 10-01-2009 08:08 PM

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?

dm24047 10-01-2009 08:39 PM

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

Compliments of the Bisman LUG

DrLove73 10-02-2009 03:09 AM

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



All times are GMT -5. The time now is 07:32 AM.