58

I am not able to understand the answer for this question: "What's the difference between cron and crontab." Are they both schedulers with one executing the files once and the other executing the files on a regular interval OR does cron schedule a job and crontab stores them in a table or file for execution?

Wiki page for Cron mentions :

Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule.

But wiki.dreamhost for crontab mentiones :

The crontab command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically. It reads a series of commands from standard input and collects them into a file known as a "crontab" which is later read and whose instructions are carried out.

Specifically, When I schedule a job to be repeated : (Quoting from wiki)

1 0 * * *  printf > /var/log/apache/error_log

or executing a job only once

at -f myScripts/call_show_fn.sh 1:55 2014-10-14

Am I doing a cron function in both the commands which is pushed in crontab OR is the first one a crontab and the second a cron function?

codeforester
  • 39,467
  • 16
  • 112
  • 140
NoobEditor
  • 15,563
  • 19
  • 81
  • 112

1 Answers1

71

cron is the general name for the service that runs scheduled actions. crond is the name of the daemon that runs in the background and reads crontab files. A crontab is a file containing jobs in the format

minute hour day-of-month month day-of-week  command

crontabs are normally stored by the system in /var/spool/<username>/crontab. These files are not meant to be edited directly. You can use the crontab command to invoke a text editor (what you have defined for the EDITOR env variable) to modify a crontab file.

There are various implementations of cron. Commonly there will be per-user crontab files (accessed with the command crontab -e) as well as system crontabs in /etc/cron.daily, /etc/cron.hourly, etc.

In your first example you are scheduling a job via a crontab. In your second example you're using the at command to queue a job for later execution.

Ben Whaley
  • 32,811
  • 7
  • 87
  • 85
  • so..in my example commands....both are `cron` which are stored in `crontab` file??? – NoobEditor Feb 14 '14 at 20:51
  • Your first example would go in a crontab file. You'd add it via **crontab -e**. The second example uses the **at** command and would not be in a crontab. – Ben Whaley Feb 14 '14 at 21:30
  • so second example is neither `cron` not `crontab` because of **at**?? – NoobEditor Feb 14 '14 at 21:38
  • 7
    Yes, that's correct. You can use **at** with no **cron** daemon running. **at** is typically used for one-time actions while **cron** is for recurring tasks. – Ben Whaley Feb 14 '14 at 21:48
  • 7
    Excellent teardown. The most concise and lucid description I've ever run across. – J.M. Janzen Feb 07 '17 at 14:40
  • After editing with `crontab -e`, my user's crontab file was located at `/var/spool/cron/crontabs/`. This must have changed in the last few years. Also, there's a default editor selector (nano vs vim vs etc) for my crontab. This setting is located at `/home//.selected_editor` (or `~/.selected_editor') and changeable via the `select-editor` command – abelito Dec 04 '21 at 15:49