Not sure about older versions of Ubuntu, but recent ones also allow the use of @reboot
(see e.g. here in the Ubuntu Wiki, scroll down a little or Ctrl+F your way to @reboot).
This might be a useful choice for when you want a user to be able to run their own commands at boot time without either having to become root (or have whoever has access to the root account do it for them) or even to have to login. If it works, it works without logging in.
So, as "bob", type crontab -e
, and then add a new line at the bottom of the file that opens, such as:
# bottom of bob's crontab
@reboot /path/to/a_small_app
In case it doesn't work, you might want to check your environment variables, especially PATH
. I usually set HOME
and PATH
explicitly atop the crontab. Something like:
# top of bob's crontab
HOME=/home/bob
PATH=/home/bob/.local/bin:/usr/local/bin:/usr/bin:/bin
A technique for figuring out why it might not be working:
# bottom of bob's crontab
* * * * * /path/to/a_small_app 2>&1 | tee /tmp/a_small_app.log # will run every minute
... and then open /tmp/a_small_app.log
in your favorite editor after 60 seconds to see if there's any useful info in there.
When trying out @reboot
today to initiate a tmux session within which the command-to-be-run should live, I've stumbled over a stubborn script today, which ended up working with this little trick. Showing it in combination with the above logging thing:
@reboot tmux new-session -d -s mysession "bash -c '/path/to/a_small_app 2>&1 | tee /tmp/a_small_app.log'"