I’ve never really understood the linux startup process (and still don’t), so it’s always been difficult to figure out how start things on every reboot.  Luckily, crontab is a beautiful thing that allows one to do just this and more!  Say I have a script that I’d like to run as admin on every reboot.  All I have to do is:

> sudo crontab -e

then add the line:

@reboot /home/bob/local/scripts/something.sh

and on upon every reboot the script will run.  What’s even cooler is that there are separate crontabs for each user.  So instead of using sudo in the above command if you simply use ‘crontab -e’ you will edit the current user’s crontab. For instance I have two entries in my server’s current crontab that periodically deletes a huge log file, and starts my ipython notebook server:

# m h  dom mon dow   command
10 06 * * * /home/bob/local/scripts/delxsessionerrs.sh
@reboot /home/bob/local/scripts/ipynotebook.sh

The first command tells the system to run delxsessionerrs.sh at 6:10am every day, the second line launches ipynotebook.sh on every reboot. Now I imagine one could insert the commands directly into the crontab, but I prefer the above script method.


Comments

comments powered by Disqus