55

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.

3 Answers 3

83

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
5
  • Is there any way to see details with root user privilege . Because I didn't have root privilege .
    – kannanrbk
    Jun 21, 2012 at 4:41
  • You would need to have your jobs keep their own completion log. Edited to show example.
    – Stecman
    Jun 21, 2012 at 4:52
  • 2
    Does this answer apply for cron jobs running as root as well as for those running as my local user?
    – Richard
    May 16, 2016 at 14:08
  • @Richard - Yep, Cron logs jobs for all users in syslog (at least under Debian): sudo grep CRON /var/log/syslog to see them, or replace root with the user you want to see jobs from in the second command in my answer.
    – Stecman
    May 18, 2016 at 2:02
  • 3
    no syslog path on my CentOS, but it directly in /var/log/cron file instead
    – HendraWD
    Feb 27, 2018 at 6:23
13

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

3
  • 2
    I don't see any file or directory with the name cron on the path /var/log/ Jul 2, 2017 at 10:50
  • 2
    I think answers should explicitly specify what distribution they are related to!!!
    – Celdor
    Jan 22, 2019 at 16:30
  • On CentOS, Redhat and Amazon Linux cron logs are written to /var/log/cron. Source: cronitor.io/cron-reference/where-are-cron-logs-stored
    – Oskar
    Feb 20, 2022 at 0:03
6

CentOs, sudo grep CRON /var/log/cron

1
  • or even better sudo grep CRON /var/log/cron | grep \(user\)
    – Celdor
    Jan 22, 2019 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.