FreeBSD

What is Crontab in FreeBSD

This tutorial shall introduce the crontab command-line utility in FreeBSD. With Crontab, you can set up or remove the tables that propagate the cron daemon. It can also be used to edit the files in /var, which cannot be configured directly. It is primarily used to schedule and automate command executions.

Crontab can be granted to each user account. The user accounts which can use the crontab command are listed in the allow file if it is available. Else, either the deny file governs what users are restricted from using this command, or the command would only be available to all or no users (barring the superuser), depending upon certain configuration variables. \

Crontab options/switches

Using a crontab without any option displays the crontab of the user.

Using with –u option:

The –u option, when added to the crontab with a username, edits the crontab of that user.

Using with –l option:

Adding the –l option to the crontab command yields crontab on the standard output.

Using with –r option:

Using the –r option with the crontab command erases your crontab. Before actually deleting the crontab, you’ll be asked for confirmation.

Using with –f option:

Executing the crontab command with the –f option deletes your crontab without asking for confirmation first, so use with caution.

Using with –e option:

Use the –e option with crontab to make changes to the current crontab, and installs the modified crontab once you exit the editor.

Crontab files

The files relevant to crontab utility are as under:

  1. The file located at /var/cron/allow shows what users are allowed to use crontab.
  2. The file located at /var/cron/deny displays what users have their crontab privileges restricted.
  3. Lastly, the file at /var/cron/tabs lists the crontab tables.

Syntax:

The syntax for using the Crontab command is as under:

$ crontab [-u user] file
$ crontab [-u user] { -l | -r [-f] |-e }

Conclusion

With crontab, users can schedule and automate the commands to be executed. The cron utility works in the background and runs any commands that are listed in a crontab.

If you want to start a new crontab file instead of using a template, you can use the crontab command with the –e option.

About the author

Younis Said

I am a freelancing software project developer, a software engineering graduate and a content writer. I love working with Linux and open-source software.