Tag Archives: autostart

Autostart any Script using crontab

This guide is targeted at Raspian (Raspberry Pi) but it will work with most Linux distributions.

First, create your script using your editor of choice. Make sure you know the location of it!

nano superscript.sh

 

Make it executable:

chmod +x superscript.sh

 

Now edit your crontab file using this command:

crontab -e

 

Go to the bottom of the file and add the following line (lines starting with a # will be ignored):

@reboot sh /home/pi/superscript.sh > /home/pi/superscript-cronlog 2>&1
@reboot
Tells crontab to execute this command after a boot
sh
Uses sh to execute your script. Of course you can use any other shell too.
/home/pi/superscript.sh
Path to your script
>
Writes the output of your script into the file specified on the right-hand side (green part)
/home/pi/superscript-cronlog
Path to your log file
2>&1
Makes sure that error messages (stderr) are also written to the log file. More information.

 

Reboot your computer and it should work!