[Last Call] Learn how to a build a cloud-first strategyRegister Now


How to create a log for the result of the scheduled script that run everynight in Linux?

Posted on 2011-05-02
Medium Priority
Last Modified: 2012-05-11
This is using SLES 11 SP1 system. There is a cron job using a script to do some copying, with command as follows:

  cd /backup
  cp -rp accounts /media/disk/$(date +"%Y-%d-%b")/


Assuming my log file is in /backup/log folder, how can I log the result of the above job? This is to check what time the above cron job complete, whether is successful or failed?
Question by:Balack
LVL 31

Accepted Solution

farzanj earned 1500 total points
ID: 35512017
You need to redirect any message send to the standard error by using 2> redirection.

You can accomplish logging by using the script below with minor/some modifications.
cd /backup
  cp -rp accounts /media/disk/$(date +"%Y-%d-%b")/ 2>> /backup/log/file
  if [[ $? != 0 ]]
      DATE=$(date +"%Y-%d-%b")
      echo "$DATE : Failed" >> /backup/log/file
      DATE=$(date +"%Y-%d-%b")
      echo "$DATE : Completed successfully" >> /backup/log/file

Open in new window


Author Closing Comment

ID: 35784214
Sorry for the delay, it works perfectly

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question