Grimoire-
Command
.es

GNU+Linux command memo

Run a command at startup

Lancer une commande au démarrage.

- via rc.local

# vi '+%s/^exit 0/$cmd\rexit 0/' +:wq /etc/rc.local (1)
1 Add your command before the exit 0 in the /etc/rc.local file of your system.

- via crontab

# echo "@reboot $cmd" >> /etc/crontab  (1)
1 crontab can starts commands at startup with the special keyword @reboot. See man 5 crontab.

- or via systemd

Create a /lib/systemd/system/$name.service file :

[Unit]
Description=My startup time service
[Service]
ExecStart=/path/to/sbin/startup-time.sh
[Install]
WantedBy=multi-user.target
# chmod u+x /path/to/sbin/startup-time.sh (1)
# systemctl start $name.service (2)
# systemctl enable $name.service (3)
1 Make the script en executable one
2 Start the service, it will execute the script once
3 Enable the service, to make it starting at each reboot

See man systemd.unit for more info.