Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cron jobs: Monitor time it takes for jobs to finish

I'm doing a research project that requires I monitor cron jobs on a Ubuntu Linux system. I have collected data about the jobs' tasks and when they are started, I just don't know of a way to monitor how long they take to finish running.

I could calculate the time of finishing the task minus starting it with something like this but that would require doing that on the Shell scripts of each cron job. That's not necessarily difficult by any means but it seems a little silly that cron wouldn't in some way log this, so I'm trying to find an easier way :P

tl;dr Figure out time cron jobs take from start to finish

like image 467
connergdavis Avatar asked Aug 15 '12 17:08

connergdavis


2 Answers

You could just put time in front of your crontabs, and if you're getting notifications about cron script outputs, it'll get sent to you.

For example, if you had:

0 1,13 * * * /maint/run_webalizer.sh

add time in front

0 1,13 * * * time /maint/run_webalizer.sh

and you'll get some output that looks like (the "real" is the time you want):

real    3m1.255s
user    0m37.890s
sys     0m3.492s

If you don't get cron notifications, you can just pipe the output to a file.

like image 101
Jon Lin Avatar answered Sep 30 '22 11:09

Jon Lin


man time. Maybe you can create a wrapper and tell Cron to use it as your "shell" or something like that.

like image 21
tripleee Avatar answered Sep 30 '22 12:09

tripleee