Linux crontab and job scheduling
In Linux, we can not ignore the usages of cron. It’s command line utility and it helps to schedule tasks. Those tasks will execute periodically pas per the configuration. In this article I am just mentioning the basic operation of crontab command.
Crontab is the program used to install, remove or list the tables used to drive the cron daemon. Cronjobs are predefined jobs which are running periodically according to the settings we have done previously.
# crontab [-u user] [-l | -r | -e] [-i] [-s]
Important switches with example
Append the name of the user whose crontab is to be tweaked. If this option is not given, crontab examines “your” crontab, i.e., the crontab of the person executing the command. Note that su(8) can confuse crontab and that if you are running inside of su(8) you should always use the -u option for safetyâ€™s sake. The first form of this command is used to install a new crontab from some named file or standard input if the pseudo-filename “-” is given.
Lists all jobs.
[[email protected] ~]# crontab -l no crontab for root
For a user
[[email protected] ~]# crontab -u crybit -l no crontab for crybit
This option is for editing the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automatically.
[[email protected] ~]# crontab -e
For a user:
[[email protected] ~]# crontab -u crybit -e
To remove current crontab. Do it carefuly, it will remove all cronjobs under the current user.
[[email protected] ~]# crontab -r no crontab for root
For a user:
[[email protected] ~]# crontab -u crybit -r no crontab for crybit
This option modifies the -r option to prompt the user for a â€™y/Yâ€™ response before actually removing the crontab.
[[email protected] ~]# crontab -ir crontab: really delete root's crontab? y no crontab for root
For a user:
[[email protected] ~]# crontab -u crybit -ir crontab: really delete crybit's crontab? y no crontab for crybit
It will append the current SELinux security context string as an MLS_LEVEL setting to the crontab file before editing / replacement occurs – see the documentation of MLS_LEVEL in crontab(5).
[[email protected] ~]# crontab -u crybit -es no crontab for crybit - using an empty one crontab: installing new crontab [[email protected] ~]# crontab -u crybit -l MLS_LEVEL=s0-s0:c0.c1023
That’s it..!! 🙂