The Cron task planner with the variable time specification “@reboot” is suitable for scripts and background programs that are to be executed when the system is started.
There are tasks under Linux that would be basically simple solution but is anything but trivial because of the differences between the Linux distributions. This includes starting your own programs and scripts when the system boots. Actually, this should always be done via the init daemon with a suitable start script. If none is available for the desired purpose, you are forced to write one yourself. But there is an easier way.
Debian and Linux distributions derived from it, such as Ubuntu and Raspbian , provide the file “/etc/rc.local” for their own scripts and programs. What is entered there before the final line “exit 0” is carried out by the system with root rights during boot.
The system ignores all errors and skips the rest of the file from the first faulty command so that the information in “rc.local” does not affect the system start. If something does not work right away, troubleshooting in the “rc.local” is therefore difficult. And for distributions outside the Debian family tree, the start method is irrelevant anyway, since there is no “rc.local” there.
A slightly better, also uncomplicated method of running scripts and programs automatically when booting is provided by the Cron task scheduler. This supports the keyword “@reboot” as time specification, which defines the system start as the time. Whether a restart or a cold start does not matter.
One advantage is that Cron cannot only execute the entered commands as root. Every user of the system can put autostart commands in their own cron table, which are then executed in this user context.
To edit your own cron table, type
in the terminal. With
sudo crontab -e
edit cron entries for the root account. In the called editor you define an autostart call with “@reboot” at the beginning of the line and the exact path to the script or the program file:
As in the rc.local “you cannot start any graphic applications, not even programs that require a terminal. However, there is a trick with the help of the screen tool to start terminal programs in the background. For example, the line
@reboot /usr/bin/screen -d -m rtorrent
the bit torrent client rtorrent in a screen session, which you can then use
can bring them to the foreground at any time.