I am making a program for the Raspberry Pi to use, as part of its installation, it need to add a task to crontab so that it will run on bootup.

I know if I type in crontab -e then add the line "@reboot file/to/program" to the bottom it will do it.

But how do I do it with just a command in the terminal for my installation script to use?

3 Answers 3


This isn't particularly specific to the Raspberry Pi, and a bit of googling reveals some very complete cron overviews. From your description, it sounds like you want to edit the system-wide crontab (e.g.sudo nano /etc/crontab) to add the @reboot clause.


I have a number of crons that I add via my install script. Works perfect.

sudo sh -c 'cat <<EOF > /var/spool/cron/crontabs/root
00 * * * * curl http://example.org/ping/`hostname`
* * * * * /usr/bin/php /var/www/crontab.php
sudo /etc/init.d/cron restart

If you want to do a manual check whether those crons have been added correctly:

sudo crontab -e

shows that everything is added as it should be.


Yet another option- you can place a file in /etc/cron.d/. The advantage of this is you own the whole file, so it's easier to install it and not worry about breaking other entries.


cat /etc/cron.d/hello
*/5 * * * * pi /home/pi/hello.sh

Note entries in system-level places like this also specify the username.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.