How-to: Figure out if crontab and at is correctly set up
February 20th, 2009I 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 proceed through the rest of the steps – they are meant as suggestions to solutions. And if you have it working they might break it. That means; no guarantees!
Gnome-schedule is a front-end to crontab and atd, and it is those that actually start 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 either be in /etc/cron.allow (if it exists) or not be in /etc/cron.deny (if it exists). If neither exist only root can use crontab – this is not true for my system, but might be for Ubuntu.
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>+DTo list current jobs try:
$ atqIf 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/




July 26th, 2009 at 18:45
Ok. Till what you have said here, has been done.
Now, the question is, if I want to start my torrent client or my music player at a scheduled time, how do I go about it? I typed the program command, but nothing happens, except that when the time comes, it gets removed from the task list..
I guess I am overlooking something, but I am not able to find out what that is.
Can you please help me out?
July 28th, 2009 at 1:40
You have to use the latest version of gnome-schedule (2.1.0), you can get the source from http://gnome-schedule.sf.net. It is has probably not been packed for your distro yet, so post a bug or request something happens if it already exists.
Otherwise execute programs like this: export DISPLAY=:0 && command-name
Check out the ubuntu wiki on this: https://help.ubuntu.com/community/CronHowto
- gaute
July 29th, 2009 at 1:41
OMG! It is working!
That was exactly what I was overlooking… that export display variable.
Thank you so much, man.
And keep up the good work!
October 16th, 2009 at 17:38
Thanks guys,
I had the same problem trying to get BitTornado to download at a set time. A similar solution worked for me except the code missing off the front of mine was “env DISPLAY=:0″ (minus the quotes) so the full code reads:
env DISPLAY=:0 /usr/bin/btdownloadgui.bittornado /home/user/torrents/filename.torrent
(need to replace “user” with your username and “filename” with correct filename).
I’m using Ubuntu 9.04
More explanation of env DISPLAY=:0 can be found here https://help.ubuntu.com/community/CronHowto towards the bottom – although you should read the whole page if you’re new to this (like me).