How to run scripts on #Linux start up? crontab @reboot  #devops

Hits: 1072

Nothing like a good Geeky command after the Yom Kippur 25 hour fast! Ubuntu loves to run apt-daily.service on Startup, which messes with devops pre-installations. In My case I want to run docker-machine.

 

Turn off auto updates
edit file 20-auto-upgrades in /usr/share/unattended-upgrades

Turn the service back on after 20 minutes

 

or /etc/apt/apt.conf.d

https://www.garron.me/en/linux/turn-off-stop-ubuntu-automatic-update.html

 

So the plan is to run a cron job that runs during startup that kills apt-daily.service.

 

See also

How to disable `apt-daily.service` on Ubuntu cloud VM image? – #DEVOPS

These special time specification “nicknames” are supported, which
replace the 5 initial time and date fields, and are prefixed by the ’@’
character:
@reboot : Run once, at startup.
@yearly : Run once a year, ie. “0 0 1 1 *”.
@annually : Run once a year, ie. “0 0 1 1 *”.
@monthly : Run once a month, ie. “0 0 1 * *”.
@weekly : Run once a week, ie. “0 0 * * 0”.
@daily : Run once a day, ie. “0 0 * * *”.
@hourly : Run once an hour, ie. “0 * * * *”.

CAVEATS
In this version of cron , /etc/crontab must not be writable by any user
other than root. No crontab files may be links, or linked to by any
other file. No crontab files may be executable, or be writable by any
user other than their owner.

https://alvinalexander.com/linux/man/unix-linux-crontab-man-page-format-syntax

383 down vote One approach is to add an @reboot cron task: Running crontab -e will allow you to edit your cron. Adding a line like this to it: @reboot /path/to/script will execute that script once your computer boots up.

Source: startup – How to run scripts on start up? – Ask Ubuntu