longlytr
Posts: 1
Joined: Mon Jul 08, 2019 6:11 am

Starting shell script automatically when start up

Mon Jul 08, 2019 6:19 am

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

User avatar
DougieLawson
Posts: 39192
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Starting shell script automatically when start up

Mon Jul 08, 2019 9:29 am

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

christopholous
Posts: 14
Joined: Sat Jul 06, 2019 1:51 am

Re: Starting shell script automatically when start up

Mon Jul 08, 2019 12:15 pm

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
Last edited by christopholous on Mon Jul 08, 2019 12:23 pm, edited 1 time in total.
Your mother is so fat, the recursive function computing her mass causes a stack overflow.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Starting shell script automatically when start up

Mon Jul 08, 2019 12:21 pm

How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “Beginners”