10

no /var/log/cron ,no /var/log/cron.log on my debian7 ,Where is my logfile of crontab ?

ls /var/log/cron*
ls: cannot access /var/log/cron*: No such file or directory
14

I think on debian cron writes logs in /var/log/syslog.
If your system depends on rsyslogor syslogd you can check and uncomment either in /etc/rsyslog.conf or /etc/syslog.conf for line:

# cron.* /var/log/cron.log

and then restart services.

If your system depends on systemd for example you can check with following command:

journalctl _COMM=cron

or

journalctl _COMM=cron --since="date" --until="date"

For date format you can check journalctl.

| improve this answer | |
  • no /etc/rsyslog.con and /etc/syslog.conf in my debian7. – showkey Jun 26 '15 at 11:54
  • fot the first file it is a typo should be /etc/rsyslog.conf if you are not with systemd. – taliezin Jun 26 '15 at 12:14
  • what about sudo journalctl --since yesterday -u cron.service? What is _COMM? – dashesy Jan 11 '17 at 0:26
4

By default the output from crontab jobs are sent to the local email address of the owning user. for example: The crontab output for aUser on host www.aDomain.com would be sent to aUser@www.aDomain.com. The system uses its default mailer to accomplish the task.

You can divert this output to an alternate email address by adding a MAILTO statement within the crontab file. For example:

# Mail any output to myuser@gmail.com, no matter whose crontab this is
MAILTO=myuser@gmail.com
# Run the following command ten minutes after midnight, every day
10 0 * * *       $HOME/bin/aJob.sh 

Be careful when using an external email address to receive crontab logs. Frequently sent messages may get caught in a spam filter. You would then have to mark the messages as Not Spam for services like Yahoo, HotMail, or Gmail.

An alternate solution would be to redirect the output of your crontab commands to a file of your choice. In the example below the stdout and stderr output is sent to /tmp/aJob.log. This method eliminates the possibility of an email message being sent.

# Run the following command ten minutes after midnight, every day
10 0 * * *       $HOME/bin/aJob.sh >> /tmp/aJob.log 2>&1

Another alternative is to send stderr logs to email and stdout logs to a file. In this case you get alerted by email when your crontab commands generate unexpected error messages. The difference with the previous example is that 2>&1 is removed to allow stderr output to go to the console and therefore to email.

# Mail any output to myuser@gmail.com, no matter whose crontab this is
MAILTO=myuser@gmail.com    
# Run the following command ten minutes after midnight, every day
10 0 * * *       $HOME/bin/aJob.sh >> /tmp/aJob.log

Read more crontab tables and crontab command

| improve this answer | |
1

Since this is not tagged debian and appears in fedora searches as well, here is how to check for recent (systemd-based) fedora:

sudo systemctl status crond

Typical output

● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-09-29 16:09:21 CEST; 47min ago
 Main PID: 1167 (crond)
    Tasks: 1
   Memory: 2.8M
      CPU: 948ms
   CGroup: /system.slice/crond.service
           └─1167 /usr/sbin/crond -n

Sep 29 16:09:21 ncelrnd0216 systemd[1]: Started Command Scheduler.
Sep 29 16:09:21 ncelrnd0216 crond[1167]: (CRON) STARTUP (1.5.4)
Sep 29 16:09:21 ncelrnd0216 crond[1167]: (CRON) INFO (Syslog will be used instead of sendmail.)
Sep 29 16:09:21 ncelrnd0216 crond[1167]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 31% if used.)
Sep 29 16:09:21 ncelrnd0216 crond[1167]: (CRON) INFO (running with inotify support)

and all the logs with

journalctl --unit crond -n all
| improve this answer | |
0

Check MAILTO's inbox: /var/spool/mail/root. The cron job's execution log will remain there.

| improve this answer | |
0

2020 : Google brought me for something similar.

With distros that are using systemd, there is no more /var/log/messages or /var/log/cron.

With systemd, the journald daemon handles logging.

To see if cron is running your scripts and to follow the the log, use;

   journalctl -u cron.service -f

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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