nixers
running a shell script every time you boot linux - Printable Version
+- nixers (https://nixers.net)
+-- Forum: Operating Systems & Administration (https://nixers.net/Forum-Operating-Systems-Administration)
+--- Forum: GNU/Linux (https://nixers.net/Forum-GNU-Linux)
+--- Thread: running a shell script every time you boot linux (/Thread-running-a-shell-script-every-time-you-boot-linux)


running a shell script every time you boot linux - archery - 03-01-2017

---

i'm sure there's some sophisticated method for running a shell script at boot, but here's an easy alternative:

open /etc/crontab in a text editor (you'll need root):

$ sudo vim /etc/crontab

add this line to the bottom: @reboot root /bin/bash /root/init.sh

now, open /root/init.sh and put your shell script there.

a word of warning:

don't use the root user unless you need to. if you don't, create a new user and use it instead:

$ useradd -g users -s /bin/(zsh|bash) username

---


RE: running a shell script every time you boot linux - wsaile - 04-01-2017

Seems like a good method. Welcome to the forums.


RE: running a shell script every time you boot linux - hades - 04-01-2017

Pretty neat, although, at first glance: would @reboot only cause this to be triggered and run on a soft reboot? Would it also work on a hard power cycle?


RE: running a shell script every time you boot linux - jkl - 04-01-2017

Note that @reboot also works on BSD Unix (?) and its descendants (!).


RE: running a shell script every time you boot linux - xero - 04-01-2017

Code:
crontab -e

is how i usually edit my cron jobs.