3

I know that cron events are stored in /var/log/syslog and I can use a command like:

sudo cat /var/log/syslog | grep cron 

to see them.

I'd much rather have the system keep a separate cron log file so it doesn't do as much work watching it, as it sorts through all the syslog messages to pull out the cron notifications.

Then I want to use the watch command so I always have an open terminal window showing cron activity.

How do I make the system keep a separate /var/log/cron.log file?

7

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.

  • +1 but I wouldn't call that "trivial" :) – WinEunuuchs2Unix May 9 '18 at 20:10
  • Depends on the audience, I suppose. So I changed it to say this is the simplest way to do it. ;-) One thing I can say is that this is my default screen on my main servers: wcron with System Monitor over the top of it. Gives a great overview. Plus, I use espeak so the cron jobs announce their progress or errors. – SDsolar May 9 '18 at 23:37
  • 1: On Debian systems like Ubuntu, the extra options to cron are defined in /etc/default/cron. That is where you should have EXTRA_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
1

Every morning cron emails me a daily backup in a single .tar file attachment. At the send time it sends me a separate email with details that do NOT appear in /var/log/syslog. This might be of interest to you:

Anacron job 'cron.daily' on dell 
Anacron <MyRealName@gmail.com>
4:05 AM (15 hours ago)

to root, bcc: me 
/etc/cron.daily/daily-backup:
bin/
bin/.websync.new
bin/log-gsu-del
bin/now
bin/lid
bin/usb-suspend
bin/edmonton
bin/toggle-touchpad
bin/edmonton.2
bin/dbus-screen-lock
bin/test
bin/log-gsu-testfile
bin/one-cpu-pids
bin/dkms-gui
bin/test-parms
bin/log-gsu-zenity-test
bin/log-boot
bin/adpative-brightness-configuration-file
bin/strip-first-rec
bin/log-gsu-nautilus
bin/.websync.ver2
bin/sed-limit-file
bin/new2
bin/backup
bin/websyncExpandListArr2
bin/seconds
bin/adaptive-brightness-configuration-file
bin/sudotest
bin/testver
bin/zenity-test
bin/log-cron
bin/adaptive-brightness-config
bin/gtk-icons
bin/secSunset
bin/deltest2
bin/snakes
bin/.websync.new2
bin/indicator-sysmonitor-display
bin/strip-first-rec2
bin/894470
bin/rm2
bin/bafman
bin/NIGHTMARE
bin/gsu
bin/log-gsu-geit
bin/lock-screen-timer
bin/grab-website-images
bin/websync
bin/hotplugtv
bin/websyncExpandListArr
bin/log-hotplugtv
bin/ProgressBar
bin/summary-log
bin/cpu-top-summary
bin/yad_notification
bin/log-file
bin/log-gsu-gedit
bin/dbus-unlock-screen
bin/log-gsu-log-file
bin/log-gsu-50_r8169-ethernet
bin/deltest3
bin/start-conky
bin/testwget
bin/r8169
bin/stat.c_diff
bin/text-spinner
bin/.websync.sav
bin/log-gsu-daily-backup
bin/stat.c
bin/.websync
bin/cron-minute-test
bin/edmonton.1
bin/ListArr
tar: Removing leading `/' from member names
/usr/local/bin/
/usr/local/bin/iwlwifi-reset
/usr/local/bin/windows
/usr/local/bin/.auto-brightness-config
/usr/local/bin/zenity
/usr/local/bin/spawn-progress-multi
/usr/local/bin/full-backup
/usr/local/bin/top-of-hour-chime
/usr/local/bin/sun-hours
/usr/local/bin/kill-previous-version
/usr/local/bin/rm-kernels-debug
/usr/local/bin/sunrise
/usr/local/bin/bell/
/usr/local/bin/bell/sounds/
/usr/local/bin/bell/sounds/Slick.ogg
/usr/local/bin/bell/sounds/Blip.ogg
/usr/local/bin/bell/sounds/Positive.ogg
/usr/local/bin/bell/sounds/Amsterdam.ogg
/usr/local/bin/bell/sounds/message.ogg
/usr/local/bin/bell/sounds/bell.ogg
/usr/local/bin/bell/sounds/Mallet.ogg
/usr/local/bin/bell/sounds/Rhodes.ogg
/usr/local/bin/bell/sounds/default.ogg
/usr/local/bin/bell/bell-select-menu
/usr/local/bin/playall-bells
/usr/local/bin/testfile.touch
/usr/local/bin/cron-reboot-cycle-grub-background
/usr/local/bin/zaprestore
/usr/local/bin/zap/
/usr/local/bin/zap/hello.o
/usr/local/bin/zap/Assembly-Intro-hello/
/usr/local/bin/zap/Assembly-Intro-hello/FreeBSD/
/usr/local/bin/zap/Assembly-Intro-hello/FreeBSD/hello
/usr/local/bin/zap/Assembly-Intro-hello/FreeBSD/hello.asm
/usr/local/bin/zap/Assembly-Intro-hello/BeOS/
/usr/local/bin/zap/Assembly-Intro-hello/BeOS/hello
/usr/local/bin/zap/Assembly-Intro-hello/BeOS/hello.asm
/usr/local/bin/zap/Assembly-Intro-hello/Linux/
/usr/local/bin/zap/Assembly-Intro-hello/Linux/hello
/usr/local/bin/zap/Assembly-Intro-hello/Linux/hello.asm
/usr/local/bin/zap/hello.asm
/usr/local/bin/zapboot
/usr/local/bin/rm-kernels
/usr/local/bin/doug-rm-kernels-server
/usr/local/bin/echo
/usr/local/bin/startup-scripts/
/usr/local/bin/testver
/usr/local/bin/spawn-progress-log
/usr/local/bin/sunset
/usr/local/bin/change-attributes
/usr/local/bin/rm-kernels-server
/usr/local/bin/bottom-of-hour-chime
/usr/local/bin/rm2
/usr/local/bin/spawn-progress-bar
/usr/local/bin/Link to auto-brightness-config
/usr/local/bin/auto-brightness-config
/usr/local/bin/892077
/usr/local/bin/set-hyper-threading
/usr/local/bin/bell-menu
/usr/local/bin/display-auto-brightness
/usr/local/bin/dd
/usr/local/bin/load-default-bell
tar: Removing leading `/' from member names
/etc/cron.d/
/etc/cron.d/turn-off-hyper-threading
/etc/cron.d/anacron
/etc/cron.d/test-reboot
/etc/cron.d/php
/etc/cron.d/.placeholder
/etc/cron.d/test-directory/
/etc/cron.d/display-auto-brightness
/etc/cron.d/touch-vmlinuz
/etc/cron.d/popularity-contest
/etc/cron.d/cycle-grub-background
/etc/cron.daily/
/etc/cron.daily/bsdmainutils
/etc/cron.daily/sun-hours
/etc/cron.daily/google-earth
/etc/cron.daily/dpkg
/etc/cron.daily/update-notifier-common
/etc/cron.daily/0anacron
/etc/cron.daily/daily-backup
/etc/cron.daily/apt-compat
/etc/cron.daily/google-chrome
/etc/cron.daily/man-db
/etc/cron.daily/logrotate
/etc/cron.daily/passwd
/etc/cron.daily/apport
/etc/cron.daily/.placeholder
/etc/cron.daily/upstart
/etc/cron.daily/mlocate
/etc/cron.daily/popularity-contest
/etc/cron.daily/cracklib-runtime
/etc/cron.hourly/
/etc/cron.hourly/.placeholder
/etc/cron.monthly/
/etc/cron.monthly/0anacron
/etc/cron.monthly/.placeholder
/etc/crontab
/etc/cron.weekly/
/etc/cron.weekly/apt-xapian-index
/etc/cron.weekly/update-notifier-common
/etc/cron.weekly/0anacron
/etc/cron.weekly/man-db
/etc/cron.weekly/.placeholder
/etc/cron.weekly/fstrim
tar: Removing leading `/' from member names
/etc/systemd/
/etc/systemd/system/
/etc/systemd/system/graphical.target.wants/
/etc/systemd/system/graphical.target.wants/accounts-daemon.service
/etc/systemd/system/dbus-org.freedesktop.ModemManager1.service
/etc/systemd/system/sysinit.target.wants/
/etc/systemd/system/sysinit.target.wants/brltty.service
/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service
/etc/systemd/system/sysinit.target.wants/resolvconf.service
/etc/systemd/system/sysinit.target.wants/friendly-recovery.service
/etc/systemd/system/bluetooth.target.wants/
/etc/systemd/system/bluetooth.target.wants/bluetooth.service
/etc/systemd/system/dbus-org.freedesktop.thermald.service
/etc/systemd/system/printer.target.wants/
/etc/systemd/system/printer.target.wants/cups.service
/etc/systemd/system/multi-user.target.wants/
/etc/systemd/system/multi-user.target.wants/unattended-upgrades.service
/etc/systemd/system/multi-user.target.wants/cron.service
/etc/systemd/system/multi-user.target.wants/tlp.service
/etc/systemd/system/multi-user.target.wants/dns-clean.service
/etc/systemd/system/multi-user.target.wants/ufw.service
/etc/systemd/system/multi-user.target.wants/rsyslog.service
/etc/systemd/system/multi-user.target.wants/cgproxy.service
/etc/systemd/system/multi-user.target.wants/snapd.firstboot.service
/etc/systemd/system/multi-user.target.wants/cups.path
/etc/systemd/system/multi-user.target.wants/pppd-dns.service
/etc/systemd/system/multi-user.target.wants/snapd.service
/etc/systemd/system/multi-user.target.wants/smartd.service
/etc/systemd/system/multi-user.target.wants/whoopsie.service
/etc/systemd/system/multi-user.target.wants/anacron.service
/etc/systemd/system/multi-user.target.wants/cgmanager.service
/etc/systemd/system/multi-user.target.wants/atd.service
/etc/systemd/system/multi-user.target.wants/lm-sensors.service
/etc/systemd/system/multi-user.target.wants/cups-browsed.service
/etc/systemd/system/multi-user.target.wants/remote-fs.target
/etc/systemd/system/multi-user.target.wants/ModemManager.service
/etc/systemd/system/multi-user.target.wants/NetworkManager.service
/etc/systemd/system/multi-user.target.wants/thermald.service
/etc/systemd/system/multi-user.target.wants/avahi-daemon.service
/etc/systemd/system/multi-user.target.wants/snapd.autoimport.service
/etc/systemd/system/multi-user.target.wants/snapd.core-fixup.service
/etc/systemd/system/multi-user.target.wants/snapd.boot-ok.service
/etc/systemd/system/multi-user.target.wants/binfmt-support.service
/etc/systemd/system/multi-user.target.wants/networking.service
/etc/systemd/system/multi-user.target.wants/vnstat.service
/etc/systemd/system/dbus-org.freedesktop.Avahi.service
/etc/systemd/system/display-manager.service.wants/
/etc/systemd/system/display-manager.service.wants/gpu-manager.service
/etc/systemd/system/timers.target.wants/
/etc/systemd/system/timers.target.wants/apt-daily.timer
/etc/systemd/system/timers.target.wants/snap-repair.timer
/etc/systemd/system/timers.target.wants/snapd.refresh.timer
/etc/systemd/system/timers.target.wants/apt-daily-upgrade.timer
/etc/systemd/system/getty.target.wants/
/etc/systemd/system/getty.target.wants/getty@tty1.service
/etc/systemd/system/syslog.service
/etc/systemd/system/sockets.target.wants/
/etc/systemd/system/sockets.target.wants/avahi-daemon.socket
/etc/systemd/system/sockets.target.wants/uuidd.socket
/etc/systemd/system/sockets.target.wants/snapd.socket
/etc/systemd/system/sockets.target.wants/cups.socket
/etc/systemd/system/sockets.target.wants/acpid.socket
/etc/systemd/system/sockets.target.wants/apport-forward.socket
/etc/systemd/system/default.target.wants/
/etc/systemd/system/default.target.wants/ureadahead.service
/etc/systemd/system/display-manager.service
/etc/systemd/system/hibernate.target.wants/
/etc/systemd/system/hibernate.target.wants/anacron-resume.service
/etc/systemd/system/dbus-org.bluez.service
/etc/systemd/system/network-online.target.wants/
/etc/systemd/system/network-online.target.wants/networking.service
/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service
/etc/systemd/system/final.target.wants/
/etc/systemd/system/final.target.wants/snapd.system-shutdown.service
/etc/systemd/system/sleep.target.wants/
/etc/systemd/system/sleep.target.wants/tlp-sleep.service
/etc/systemd/system/paths.target.wants/
/etc/systemd/system/paths.target.wants/acpid.path
/etc/systemd/system/suspend.target.wants/
/etc/systemd/system/suspend.target.wants/anacron-resume.service
/etc/systemd/system/hybrid-sleep.target.wants/
/etc/systemd/system/hybrid-sleep.target.wants/anacron-resume.service
/etc/systemd/user/
/etc/systemd/resolved.conf
/etc/systemd/network/
/etc/systemd/sleep.conf
/etc/systemd/system.conf
/etc/systemd/bootchart.conf
/etc/systemd/logind.conf
/etc/systemd/journald.conf
/etc/systemd/user.conf
/etc/systemd/timesyncd.conf
tar: Removing leading `/' from member names
/lib/systemd/system-sleep/
/lib/systemd/system-sleep/iwlwifi-reset
/lib/systemd/system-sleep/r8169-reset
/lib/systemd/system-sleep/wpasupplicant
/lib/systemd/system-sleep/sound
/lib/systemd/system-sleep/hdparm
/lib/systemd/system-sleep/display-auto-brightness
tar: Removing leading `/' from member names
/etc/rc.local
tar: Removing leading `/' from member names
/etc/default/grub
Desktop/
Desktop/Link to websync
Desktop/Link to MyEmployer Expense Report.xlsx
Desktop/Link to bafman
Desktop/Lock Screen Timer
Desktop/Link to To-Do List.odt
Desktop/IG.ods
Desktop/Link to auto-brightness-config
Desktop/KillDuplicate
Desktop/Conky
Desktop/Link to Payroll Hours.ods
Documents/34 Shaunessy repairs.odt
Documents/Edmotnon TV Channels.ods
Documents/Fan Control.odt
Documents/intel_cstate.idle_max=1.odt
Documents/Little Mermaid Pez.odt
Documents/Music File Diff.odt
Documents/Sorry I missed Thanksgiving Dinner.odt
Documents/Stanley Cup 2017.odt
Documents/To-Do List.odt
.asunder
.asunder_album_artist
.asunder_album_genre
.asunder_album_title
.BafmanDirs
.bafmanDirs
.bafmanDirs~
.BafmanDirs.sav
.bafmanDirs.sav
.bafmanDirs.sav2
.bafmanDirs.sav3
.bafmanDirs.sav4
.bafmanFiles
.bafmanFiles~
.bafmanFiles.sav
.bafmanFiles.sav2
.bafmanFiles.sav3
.bafmanFiles.sav4
.bafmanLog
.bafmanNdx
.bafmanSort
.bash_history
.bash_logout
.bashrc
.conkyrc
.conkyrc~
.dmrc
.dpkg.list
.gksu.lock
.ICEauthority
.ilg-config
.indicator-sysmonitor.json
.last-text-spinner
.lesshst
.mbr.sav
.mtab.fuseiso
.nvidia-settings-rc
.packages
.profile
.selected_editor
.sudo_as_admin_successful
.Wammu
.websync
.websync~
.websync.bad.sort
.websyncNdx
.websync.sav
.websyncSort
.wget-hsts
.Xauthority
.xinputrc
.xscreensaver
.xsession-errors
.xsession-errors.old

You can search within AU on how to setup cron email. If you are interested I can dig up the Q&A here in AU for how I setup the daily-backup using cron.

  • Wow, that is cool. TMI for right now, but I'll remember you posted this answer so I can come back to it. – SDsolar Oct 19 '17 at 2:09

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.