How-to: Figure out if crontab and at is correctly set up / 20 Feb 2009

I have gotten alot of different bug reports and problems sent to me when people try to use gnome-schedule, and quite a few of them are actually crontab and atd problems; mostly just them not being there at all. This post tries to give you an idea about how you can figure out what is wrong; or how it is supposed to work. Exactly how to set up crontab and at differs for all distributions and they all have their own tutorials.

If something works; don’t fix it!

No guarantees! - this could possibly break everything.

Gnome-schedule is a front-end to crontab and atd, and it is those that actually run the tasks. They have both been around since the beginning of time and were made for the command line, and don’t have any graphical interface.

Crontab is responsible for recurring tasks, scheduled for instance for ‘Every minute’ or ‘Every hour’.. but also quite complex expressions like every second minute of every fifth hour every 13th day of the month, but only if its wednesday. Atd schedules one-time tasks like ‘tomorrow’ or 24th of December.

Crontab

First you need to have crontab installed (there are several; vixie-cron and dcron works well) use your package manager for this. After having installed it you have to tell your system that the cron daemon should be started at system start, check with your distro on how to do this.

To figure out if the crontab daemon is running you can do the following in a terminal:

$ ps aux | grep cron

This should give you a line ending with something similar to: ‘/usr/sbin/crond’. If not; crontab is not running and you should make sure it is set up like your distro told you.

To check if it is installed you can do:

$ crontab -l

If this command is found; crontab is installed. (The output: no crontab for [username] means crontab is installed)

You need to make sure the crontab command has its SETUID bit set; to check do:

$ ls -l `which crontab` The output should be similar to (the first -rwsr-xr-x letters should be exactly like this): -rwsr-xr-x 1 root root 10076 2007-11-15 19:21 /usr/bin/crontab

You can fix this by doing (as root):

$ chmod +s `which crontab`

The cron.allow and cron.deny files: According to the Ubuntu wiki your user must be in /etc/cron.allow (if it exists) or not in /etc/cron.deny (if it exists). If neither exist, depending on implementation or distribution, only root can use crontab - this is not the case for Ubuntu or Arch Linux.

To make a test task manually you can do the following commands:

$ crontab -e You now get to edit a file, write this line: * * * * * echo "Does this work?" > ~/test

See this crunchbang tutorial for details on what this does.

.. wait a minute ..

Check if there exists a file in you home directory, test, with the contents “Does this work?”. If it does, crontab is set up correctly. In that case, delete your crontab:

$ crontab -d

At

Install at and set it up, refer to you distributions documentation.

Check if atd is running:

$ ps aux | grep atd

As with crontab; this should give you a line ending with ‘/usr/sbin/atd’. If not; at is not running, make sure it is installed and refer to your distro for starting the atd service.

To check if at is installed do:

$ at -V

This should give you:

at version 3.1.9 Bug reports to: rmurray@debian.org (Ryan Murray) Garbled time

If not; at is not installed, refer to your distro for installing it through the package manager.

At should also have the SETUID bit set;

$ ls -l `which at` This should give (the -rwsr-sr-x part should be exactly like this): -rwsr-sr-x 1 daemon daemon 37660 2006-05-31 06:40 /usr/bin/at

Add it with (as root):

$ chmod +s `which at`

To try and make a task; do:

$ at 22:00 19.02.2009 # replace the date with something in the very near future You know get a at prompt: at> echo "I work" > ~/at_test at> <Ctrl>+D To list current jobs try: $ atq If a job shows up now it worked.

Wait for the scheduled time to pass and check the contents of at_test in your home dir; if it is there it worked.

Make sure that you are not listed in /etc/at.deny and that if you have something like an /etc/at.allow file, you are listed. Refer to the at man page.

Other resources:

http://en.wikipedia.org/wiki/At_(Unix)
http://en.wikipedia.org/wiki/Cron

Crontab man page - http://www.manpagez.com/man/5/crontab/
At man page - http://linux.die.net/man/1/at

Ubuntu Wiki - https://help.ubuntu.com/community/CronHowto
Crunchbang Tutorial - http://crunchbang.org/archives/2007/10/26/howto-setup-a-crontab-file/