The crontab command and switches with example

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.

Syntax:

# crontab [-u user] [-l | -r | -e] [-i] [-s]

Important switches with example:

1, -u

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.

2, -l

The current crontab will be displayed on standard output.
Example:

[[email protected] ~]# crontab -l
no crontab for root

For a user:

[[email protected] ~]# crontab -u crybit -l
no crontab for crybit

3, -e

This option is used to edit 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.
Example:

[[email protected] ~]# crontab -e

For a user:

[[email protected] ~]# crontab -u crybit -e

4, -r

The current crontab will be removed. Do it carefuly, it will remove all cronjobs under the current user.
Example:

[[email protected] ~]# crontab -r
no crontab for root

For a user:

[[email protected] ~]# crontab -u crybit -r
no crontab for crybit

5, -i

This option modifies the -r option to prompt the user for a ’y/Y’ response before actually removing the crontab.
Example:

[[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

6, -s

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).
Example:

[[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..!! 🙂

Related links:
list cronjobs running under a user
Examples of Job Scheduling Using Crontab

More:
ls, head, tail, top, ps, find, crontab, groupdel, groupmems, groupmod, useradd , usermod , chgrp, chown

Arunlal Ashok

Linux Server Administrator. I'm dealing with Linux servers since 2012. I started this blog to share and discuss my ideas with the world. Check My Profile!! in uPwork (oDesk) and let me know if you need any assistance. Thanks!!

You may also like...

4 Responses

  1. February 1, 2014

    […] already discussed the details of CRONJOBS. Crontab is the program used to install, remove or list the tables used to drive the cron daemon. […]

  2. February 1, 2014

    […] Links: crontab command and switches list cronjobs running under a […]

  3. February 1, 2014

    […] More: groupdel, groupmems, groupmod, useradd , usermod , chgrp, chown, ls, head, tail, top, ps, find, crontab […]

  4. February 6, 2014

    […] ftp commands, groupdel, groupmems, groupmod, useradd , usermod , chgrp, chown, ls, head, tail, top, ps, find, crontab […]

Leave a Reply

Your email address will not be published. Required fields are marked *