Cronjob stopped working after apt-update/ apt-upgrade

65 Views Asked by At

I manage several Ubuntu 22.04 servers, each with multiple functioning cronjobs. However, a few days ago, I ran the apt update && apt upgrade command in all servers and rebooted them, and afterward, I observed that all the cronjobs on these servers had stopped running. I confirmed the presence of these cronjobs using the crontab -e command. In an attempt to resolve the issue, I decided to remove one of the cronjobs on one of the servers and subsequently re-added it using the same command. Surprisingly, this action revived the cronjob, but I remain uncertain about the underlying cause of this problem. How can I effectively diagnose and rectify this issue with my cronjobs?

Here's one of my crontabs for reference:

*/30 * * * * cd /home/bm/scripts/ && (echo `/bin/date` && /usr/bin/python3 /home/bm/scripts/docker-check.py) >> /home/bm/log/docker-check.log 2>&1

When I manually execute the command:

cd /home/bm/scripts/ && (echo `/bin/date` && /usr/bin/python3 /home/bm/scripts/docker-check.py) >> /home/bm/log/docker-check.log 2>&1

The cronjob works as expected, updating the docker-check.log file. However, according to the schedule */30 * * * *, it should run twice an hour. Curiously, on one of my servers, it does not follow this schedule. I had to delete the crontab and recreate it to restore its functionality.

Here is cron status in one of servers that cronjobs stopped working:

systemctl status cron
● cron.service - Regular background program processing daemon
     Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-10-19 20:48:11 UTC; 3 days ago
       Docs: man:cron(8)
   Main PID: 369 (cron)
      Tasks: 1 (limit: 4598)
     Memory: 67.6M
        CPU: 45.699s
     CGroup: /system.slice/cron.service
             └─369 /usr/sbin/cron -f -P

Oct 23 12:17:01 bm CRON[9573]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Oct 23 12:17:01 bm CRON[9573]: pam_unix(cron:session): session closed for user root
Oct 23 13:17:01 bm CRON[9581]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Oct 23 13:17:01 bm CRON[9581]: pam_unix(cron:session): session closed for user root
Oct 23 14:17:01 bm CRON[9632]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Oct 23 14:17:01 bm CRON[9632]: pam_unix(cron:session): session closed for user root
Oct 23 15:17:01 bm CRON[9644]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Oct 23 15:17:01 bm CRON[9644]: pam_unix(cron:session): session closed for user root
Oct 23 16:17:01 bm CRON[9653]: pam_unix(cron:session): session opened for user root(uid=0) by (uid=0)
Oct 23 16:17:01 bm CRON[9653]: pam_unix(cron:session): session closed for user root
0

There are 0 best solutions below