Here is the simplest way to do it:
--> Make a change in /etc/rsyslog.d/50-default.conf
with your favorite editor:
sudo gedit /etc/rsyslog.d/50-default.conf
Use Ctrl-f (find) and type cron
to find the line that says
#cron.* /var/log/cron.log
Remove the #
from that line. Then restart the service:
service rsyslog restart
From then on, all cron-related output will go to /var/log/cron.log
In order to prevent cron
from sending summary emails, place this line at the beginning of your crontab
file:
crontab -e
(Insert first line)
MAILTO=""
Then to watch it in near-real-time, first create a wcron
command:
echo "#!/bin/bash" >wcron
echo "watch -n 10 tail -n 25 /var/log/cron.log" >>wcron
chmod +x wcron
sudo cp wcron /usr/sbin
- watch -n 10 tells it to refresh the page every 10 seconds
- tail -n 25 tells it to display the last 25 entries
Whenever you want to monitor cron
in near-real-time in a terminal window, enter:
wcron
This is handy to have open in one of the 4 virtual desktops, perhaps along with System Monitor.
If you want to see more than just the launch times of longer jobs, it is easy to make the cron.log show both script start times and script end times, along with non-zero exit status messages.
How to change cron log level?
PARAPHRASED EXCERPT:
From Ubuntu 15.04 on, upstart using /etc/init/*.conf
is replaced
by systemd using configuration files in /lib/systemd/system/
and
/etc/systemd/system/
. Although a file /etc/init/cron.conf
is still
existent in Ubuntu 16.04, the script normally in use to start cron
now is /lib/systemd/system/cron.service
.
To add the -L 15
option, open the editor by using:
sudo systemctl edit --full cron
OR I RECOMMEND:
sudo gedit /lib/systemd/system/cron.service
and replace the line
ExecStart=/usr/sbin/cron -f $EXTRA_OPTS
with
ExecStart=/usr/sbin/cron -L 15 -f $EXTRA_OPTS
Then reload the configuration:
sudo systemctl restart cron
It will load it on boot also.
This enables wcron
to show all the information you need to watch your cron system as it runs your scripts on schedule.
One final idea for monitoring cron
is to teach your scripts to speak.
16.04 LTS How to make the system announce the time at the top of the hour with eSpeak
I have many of my scripts announce when they start and when they stop, or if they encounter errors.
Volume may be adjusted in the espeak
command so they can be subtle.
wcron
with System Monitor over the top of it. Gives a great overview. Plus, I useespeak
so thecron
jobs announce their progress or errors. – SDsolar May 09 '18 at 23:37/etc/default/cron
. That is where you should haveEXTRA_OPTS="-L 15"
2: If you need to modify a systemd service file (which you don't in this case), changes go under/etc/systemd/system/...
. See this answer or this. – mivk Aug 21 '18 at 16:44