Page tree
Skip to end of metadata
Go to start of metadata

Editing the crontab

sudo crontab -e

Will ask you what editor you want to use

Select an editor.  To change later, run 'select-editor'.
  1. /usr/bin/ne
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny

Next is to add your cron job to the file

The cron job runs in a certain format of minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command

As an example 

30 05 * * * /path/to/script

The script will run at 5:30AM everyday

A cron job can be user-defined as long as the name is added to the cron job

45 15 * * * roderick /home/roderick/script

At 3:45 pm everyday user roderick will run a script.


  1. This article should provide an summary and link to,

    1. The Ubuntu alternative approach to crons using the Ubuntu folder structure. For example, this could be done by dropping a script into /etc/cron.hourly/.
      1. No .(period) extensions are allowed in this case though since cron uses run-parts and run-parts --test /etc/cron.hourly/ will verify and list the files that will execute.
      2. How to specify order using the file names and numbers
    2. Basics behind scripts, how to chmod +x and that concept.
    3. The shebang (#!/bin/sh) and why you might use the sh rather than, #!/bin/bash and caveats of using sh.

  2. You should also talk about,

    1. Some programs need to run in silent mode to work.
    2. User that cron runs as.
    3. How to specify a user for cron to run as.
    4. Always testing your cron.
  3. You can also use interval times.
    ie: */5 * * * * <cmd that runs every 5 minutes>

    Useful for scripts that run at a higher frequency and cleaner than specifying exact times.

  4. Another point, under Ubuntu there is a deny and allow list for crontab. If neither exists, any user may issue crontab under their own id. This is probably safer than using sudo so we should include the instructions here.