Posted by Steve on Wed 15 Mar 2006 at 08:04
In the past we've discussed adding new init scripts to a Debian GNU/Linux system so that programs or daemons can be started when a machine is rebooted. That works very well if you're root, but for non-root users it isn't an option.
Adding init scripts is simple enough, but to write to /etc/init.d you do need to be root.
Instead of using the init scripts like this you can use the cron command scheduler which we've previously introduced.
When we covered it before we only talked about running scripts at particular intervals, such as:
There is an alternative way of adding entries to your crontab file though, using shortcuts. The shortcuts allow you to make entries that will match at particular times.
The cron shortcuts each begin with the @ character.
As an example the following will run the script /home/steve/bin/foo after the system has been rebooted regardless of the time of day:
@reboot /home/steve/bin/foo
To add an entry to your crontab file (which is the file that the cron daemon reads for per-user scheduled events) you simply execute:
crontab -e
This will open your crontab file in whichever editor you have setup. To choose a particular editor, such as emacs you could run:
EDITOR=/usr/bin/emacs crontab -e
Once you've saved your file you can view your new entrie(s) with "crontab -l":
skx@itchy:~$ crontab -l # m h dom mon dow command @reboot /home/steve/bin/foo
There are several shortcuts you can use in addition to @reboot. The full list is:
Each of these shortcuts, other than reboot, has an equivalent mapping to the "normal" crontab format. (e.g. @monthly is identical to (0 0 1 * *")
This article can be found online at the Debian Administration website at the following bookmarkable URL:
This article is copyright 2006 Steve - please ask for permission to republish or translate.