Home > bash > cron and crontab

cron and crontab

If you want a detailed presentation of the topic, refer to this post. Here I write just a short summary.

Cron is the daemon that executes scheduled commands. Crontab is the program to maintain crontab files for individual users. If we want to schedule a command, we need to use crontab.

List your sceduled tasks:

crontab -l

Edit the list of your sceduled tasks:

crontab -e

Example #1:

* * * * * date >>/tmp/date.log

It will append the date to /tmp/date.log every minute. It can be used for testing to see if you have the rights to schedule cron jobs.


{minute} {hour} {day of month} {month} {day of week} {command}

Example #2:

0 22 * * * date >>/tmp/date.log

Meaning: every day at 22h, execute the given task.

Example #3:

0 */2 * * * date >>/tmp/date.log

Execute the task every 2 hours. Notice that the minute must be specified (can be different from 0)! If you write “* */2 * * *“, it will still be executed every minute.

Calling a graphical application from crontab
If you want to launch a GUI application, you’ll get an error message: “Error: Can’t open display:”. To solve this problem, add an extra line to your crontab:

0 */2 * * * /path/to/gui_app.py >>/tmp/log.txt


Categories: bash Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: