Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 834
  • Last Modified:

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

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
Shawn3
Asked:
Shawn3
  • 4
  • 2
  • 2
1 Solution
 
duncanb7Commented:
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
 
Shawn3Author Commented:
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
 
duncanb7Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
 
Shawn3Author Commented:
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
 
Shawn3Author Commented:
This will work, but I'm looking for system level logging for all cron jobs if possible.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
 
Shawn3Author Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now