Details of last ran cron job in Unix-like systems?

LinuxLoggingCron

Linux Problem Overview


I want to get the details of the last run cron job. If the job is interrupted due to some internal problems, I want to re-run the cron job.

Note: I don't have superuser privilege.

Linux Solutions


Solution 1 - Linux

You can see the date, time, user and command of previously executed cron jobs using:

grep CRON /var/log/syslog

This will show all cron jobs. If you only wanted to see jobs run by a certain user, you would use something like this:

grep CRON.*\(root\) /var/log/syslog

Note that cron logs at the start of a job so you may want to have lengthy jobs keep their own completion logs; if the system went down halfway through a job, it would still be in the log!

Edit: If you don't have root access, you will have to keep your own job logs. This can be done simply by tacking the following onto the end of your job command:

&& date > /home/user/last_completed

The file /home/user/last_completed would always contain the last date and time the job completed. You would use >> instead of > if you wanted to append completion dates to the file.

You could also achieve the same by putting your command in a small bash or sh script and have cron execute that file.

#!/bin/bash
[command]
date > /home/user/last_completed

The crontab for this would be:

* * * * * bash /path/to/script.bash

Solution 2 - Linux

/var/log/cron contains cron job logs. But you need a root privilege to see.

Solution 3 - Linux

CentOs, sudo grep CRON /var/log/cron

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkannanrbkView Question on Stackoverflow
Solution 1 - LinuxStecmanView Answer on Stackoverflow
Solution 2 - LinuxVijay VasanthView Answer on Stackoverflow
Solution 3 - Linuxyen leidongView Answer on Stackoverflow