How to restart crontab in Linux [100% Working]

When should we restart crontab in Linux?

This is the official statement from man page of cron

cron checks each minute to see if its spool directory's
modification time (or the modification time on /etc/crontab) has changed,
and if it has, cron will then examine the modification time on all
crontabs and reload those which have changed. Thus cron need not be
restarted whenever a crontab file is modified.

So it is not required to restart crond service every time you add a new job to crontab. You can just use crontab -l to list the available jobs.

Advertisement

Although it is possible that if you are remotely modifying /var/spool/cron/crontabs/root then a crond service restart is required.

NOTE:

On Debian/Ubuntu/Mint based Linux servers you will have cron.service while on RHEL/Fedora/CentOS/AlmaLinux/RockyLinux/Fedora servers you will have crond.service.

 

Check cron/crond service status

Users expect the operating systems they use to schedule some tasks and run them when the time comes. On Linux operating systems, cron is used to create scheduled tasks. Each scheduled task is written to the crontab file (a separate crontab file is available for each user). For more information about cron, you can review this article.

These written cron tasks are actually automatically checked by the cron service every 1 minute.

foc@pardus:~$ sudo systemctl status cron.service 
● cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2022-09-07 08:36:20 +03; 53min ago
     Docs: man:cron(8)
 Main PID: 432 (cron)
    Tasks: 1 (limit: 2319)
   Memory: 832.0K
   CGroup: /system.slice/cron.service
           └─432 /usr/sbin/cron -f

Sep 07 08:36:20 pardus systemd[1]: Started Regular background program processing daemon.
Sep 07 08:36:21 pardus cron[432]: (CRON) INFO (pidfile fd = 3)
Sep 07 08:36:21 pardus cron[432]: (CRON) INFO (Running @reboot jobs)
Sep 07 09:17:01 pardus CRON[1340]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 07 09:17:01 pardus CRON[1341]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Sep 07 09:17:01 pardus CRON[1340]: pam_unix(cron:session): session closed for user root

 

How to Restart Crontab?

It is sufficient to trigger the cron service to reread the crontab file. A problem with the cron/crond service causes the crontab not to be read and not to be used in general. These are some of the commands to restart crond service, you can check them based on your distribution such as Debian or Red Hat based:

 

On Debian/Ubuntu/Mint based Linux servers:

Advertisement
$ sudo service cron restart

Or:

$ sudo systemctl restart cron

Or:

$ sudo /etc/init.d/cron restart

 

On RHEL/Fedora/CentOS/AlmaLinux/RockyLinux/Fedora servers:

$ sudo systemctl restart crond

Or (This is deprecated):

$ sudo service crond restart

 

How to Reload Crontab?

However, restarting the service may cause the active cron tasks to stop. So a better method might be to reload the service:

 

On Debian/Ubuntu/Mint based Linux servers:

$ sudo service cron reload

Or:

$ sudo systemctl reload cron

Or:

$ sudo /etc/init.d/cron reload

 

On RHEL/Fedora/CentOS/AlmaLinux/RockyLinux/Fedora servers:

$ sudo systemctl reload crond

Or (This is deprecated):

$ sudo service crond restart

 

Summary

For system administrators, cron tasks are valuable. In this article, we tried to share useful commands to restart crontab.  For more information about the cron service, you can visit the man page.

 

References

stackoverflow.com - Restarting cron after changing crontab file?

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment

X