When I put the script into my /etc/cron.hourly
directory, the system log shows that the script runs:
$ sudo grep -i cron /var/log/syslog
Jul 11 17:11:56 debian cron[962]: (CRON) INFO (pidfile fd = 3)
Jul 11 17:11:56 debian cron[962]: (CRON) INFO (Running @reboot jobs)
Jul 11 17:17:01 debian CRON[1503]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jul 11 17:57:01 debian cron[962]: (*system*) RELOAD (/etc/crontab)
Jul 11 17:58:01 debian CRON[4673]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jul 11 17:58:10 debian CRON[4669]: (CRON) info (No MTA installed, discarding output)
Jul 11 18:07:01 debian cron[962]: (*system*) RELOAD (/etc/crontab)
Jul 11 18:08:01 debian CRON[4911]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jul 11 18:08:07 debian CRON[4907]: (CRON) info (No MTA installed, discarding output)
Jul 11 18:09:01 debian cron[962]: (*system*) RELOAD (/etc/crontab)
Jul 11 18:10:01 debian CRON[4985]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
(I did a bunch of experiments, which is why you see the hourly script run more than once in an hour.)
Try this version of the script:
#!/bin/bash
# mySafeRestart : restart only if uncommunicative
if ! ping -c 1 google.com >>/var/log/error 2>>/var/log/error ; then
systemctl restart network-manager >>/var/log/error 2>>/var/log/error
fi
This version logs any messages printed by the ping
or systemctl
commands into a file called /var/log/error
. Check that file after the script runs.
Also note that different systems use different times to start hourly cron jobs; my Debian 10 system here starts cron jobs at the 17-minute mark, oddly enough, though I suppose Ubuntu MATE may use a different value.
Either way, the script did restart Network Manager for me. Go figure.