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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI think on debian
cron
writes logs in /var/log/syslog
.
If your system depends on rsyslog
or 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.
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
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
Check MAILTO
's inbox: /var/spool/mail/root
. The cron job's execution log will remain there.
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
Create a cron file in /var/log
and restart the syslog
service:
# touch /var/log/cron
# systemctl restart rsyslog
then check for logs.