Solved

Any way to log start and end time of cron jobs in RHEL 5 and up?

Posted on 2014-07-25
8
647 Views
Last Modified: 2014-07-29
I would like cron to log start and end times for each job run. I know how to do this in DEBIAN but not red hat.
0
Comment
Question by:Shawn3
  • 4
  • 2
  • 2
8 Comments
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
For example,
*/10  *     *  5,7,11  *    root command1
0     9-18  *  *       1-5  root command2
These lines will run command1 every ten minutes during May, July and November, and command2 once an hour during the working day (09:00 to 18:00) Monday to Friday.

Duncan
0
 

Author Comment

by:Shawn3
Comment Utility
Thanks Duncan, but I know how to use cron. I need to know how to get a start and end time for each of the jobs. Currently, cron logs start time and thats it.

Thanks,
Shawn
0
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
Why not make an example to the experts, other experts will come to solve issue
based your example ? otherwise, they don't know what you need

Duncan
0
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 500 total points
Comment Utility
Simplest is to write wrapper commands (or script)

The wrapper logs start date/time with the cron script's name, calls the cron script and logs end date/time.

Easiest if you give every cron script it's own log file name.

For example:

00 10 * * * echo "`date` Start of cron1" >> /home/user/cronjob1.log ; /home/user/cronjob1 ;  echo "`date` End of cron1" >> /home/user/cronjob1.log 

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Shawn3
Comment Utility
Thanks Gerwin. I have hundreds of cron jobs. I think this is a great solution, but was hoping there was a system level logging setting that I could enable.
0
 

Author Closing Comment

by:Shawn3
Comment Utility
This will work, but I'm looking for system level logging for all cron jobs if possible.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
Comment Utility
You could try setting higher log level for cron in /etc/sysconfig/crond :

CRONDARGS= -L 2

and then restarting cron : sudo service cron restart

My preference is the solution you've chosen so you can easily keep track of all jobs in one place. And the cron log itself is not accessible for users.
0
 

Author Comment

by:Shawn3
Comment Utility
I will try that...but thought it was only for debian based distros...

Tried the crondargs, but it throws an error in RHEL. I think that param is for Debian based distros. Thanks though!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

772 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