Page 1 of 1

Starting shell script automatically when start up

Posted: Mon Jul 08, 2019 6:19 am
by longlytr
Hi everyone, I'm not sure if this is good place to ask for help about shell script

I have a project require to capture logs from a devices automatically. I have screated two shell scripts and they work fine when I execute them on Terminal

The problem is I couldn't get them to execute automatically once PI boot to main screen.

Below is what i'v done so far

1) I placed 2 shell scripts in /etc/init.d/ directory
2) make them executable: chmod +x /etc/init.d/example1.sh

Appreciate if some one could help me to resolve this. Thank you very much

Re: Starting shell script automatically when start up

Posted: Mon Jul 08, 2019 9:29 am
by DougieLawson
Search Google for "systemd service site:raspberrypi.org/forums" and you'll find hundreds of examples of how to do this stuff with systemd rather than sysvinit.

Re: Starting shell script automatically when start up

Posted: Mon Jul 08, 2019 12:15 pm
by christopholous
I don't know if this is the "correct" way, but I add my scripts, programs to /etc/rc.local. Usually because they could cause issues if they start immediately, and I want a delay to prevent those issues.

For example:

sudo vim /etc/rc.local
--------------------------
sleep 6s
service sabnzbdplus start
cd /path to binary/
./somebinary &
exit 0

Re: Starting shell script automatically when start up

Posted: Mon Jul 08, 2019 12:21 pm
by RaTTuS