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

Posted on 2011-05-02
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

    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

    Sorry for the delay, it works perfectly

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    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…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now