# Adding scripts to run at startup

**URL:** <https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [April 6, 2017, 4:55pm UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412 "2017-04-06T16:55:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakebjorkekato](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jakebjorkekato](https://forum.legato.io/u/jakebjorkekato)\
**Post date:** [April 6, 2017, 4:55pm UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/1 "2017-04-06T16:55:32Z")

</div>

I am just starting with a device from Sierra Wireless (FX-30) running the Legato Linux distribution.

We have not started developing any applications yet but I am just trying to test posting some data to the internet every minute. This is done with a shell script I wrote using `curl` and a `while` loop.

By default this script cannot make connections to the internet, it is blocked by the firewall. In order to bypass this another script with the below command is ran

`iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT`

Now that my script can start and post data to the internet I wanted to run it in the background and have it start at boot. I wrote another script to

---

<div class="post-metadata">

**Author:** ![muralinagraj](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@muralinagraj](https://forum.legato.io/u/muralinagraj)\
**Post date:** [December 13, 2017, 12:02pm UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/2 "2017-12-13T12:02:17Z")

</div>

Hi jakebjorkekato,  
You have told that you had problem connecting to the internet as it was blocked by firewall and you were able to access after running the iptables rules you have mentioned.

But we are not clear what actually you are looking for !? Your last sentence **I wrote another script to** looks incomplete, Have you missed out to provide any information by mistake here ?

Regards,  
Muralidhara N.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [December 14, 2017, 1:32am UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/3 "2017-12-14T01:32:33Z")

</div>

Hi,

Do you mean you want to add some command in the init script?  
Probably you can modify /etc/init.d/mount\_early

---

<div class="post-metadata">

**Author:** ![zellefrow](https://avatars.discourse-cdn.com/v4/letter/z/c57346/32.png) [@zellefrow](https://forum.legato.io/u/zellefrow)\
**Post date:** [July 30, 2018, 4:16pm UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/4 "2018-07-30T16:16:04Z")

</div>

Hi jyijyi, I too am trying to run a script on boot and was wondering how precisely init.d/mount\_early can be modified in order to execute the script. I appreciate your help!

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [July 31, 2018, 1:23am UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/5 "2018-07-31T01:23:32Z")

</div>

How about adding your script like below in /etc/init.d/mount\_early:

* * *

# 

# Execution starts here.

# 

case “$1” in  
start)  
mount\_early\_start

```
    #try to add your script here

```

* * *

---

<div class="post-metadata">

**Author:** ![zellefrow](https://avatars.discourse-cdn.com/v4/letter/z/c57346/32.png) [@zellefrow](https://forum.legato.io/u/zellefrow)\
**Post date:** [July 31, 2018, 5:24pm UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/6 "2018-07-31T17:24:47Z")

</div>

Hi JyiJyi,

I appreciate your previous reply to my post, but I attempted to make the changes that you recommended and am still unable to launch the script on boot. I have included a screenshot of several simple shell commands that I entered into “mount\_early” that I could execute normally, but were unable to run in mount\_early. Thank you again for your help.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/1X/400f70f82a5b45f371bcafc676a1f9d369fab7f5.jpg)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [August 1, 2018, 1:48am UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/7 "2018-08-01T01:48:09Z")

</div>

I just tried on WP76 R9, I found that modifying mount\_early is not working.  
Instead I modify /etc/init.d/startlegato.sh, and I can add my command there.

* * *

case “$1” in  
start)  
echo “Legato start sequence 123”

echo 123 \> /tmp/123.txt

* * *

You can have a try there.

---

<div class="post-metadata">

**Author:** ![zellefrow](https://avatars.discourse-cdn.com/v4/letter/z/c57346/32.png) [@zellefrow](https://forum.legato.io/u/zellefrow)\
**Post date:** [August 3, 2018, 4:14pm UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/8 "2018-08-03T16:14:55Z")

</div>

Thanks jyijyi! That worked. I really appreciate your help.

---

<div class="post-metadata">

**Author:** ![lmaestro](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@lmaestro](https://forum.legato.io/u/lmaestro)\
**Post date:** [June 6, 2019, 8:09pm UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/9 "2019-06-06T20:09:17Z")

</div>

Hi all,

I was trying to do the same recently with a WP7608 module and run into the same issue:

I created an bash script, stored it at /etc/init.d/ and created a simlink into rcS.d folder with S99 runtime order. The script has execution permissions (chmod +x) but still it is not executed during modem bring up.

Did you find a solution to this other than embedding the code into another existing script?

br  
Luis

---

<div class="post-metadata">

**Author:** ![jaan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jaan](https://forum.legato.io/u/jaan)\
**Post date:** [June 8, 2019, 8:08pm UTC](https://forum.legato.io/t/adding-scripts-to-run-at-startup/2412/10 "2019-06-08T20:08:40Z")

</div>

Hi all,

I have the same problem. Working with WP77xx  
Trying to get a program running on startup with init.d. Am I missing some kind of Linux/Yocto configuration that does not allow easily to add startup scripts?

Best,

Jaan

Update:  
Or does this post apply? [Start up scripts not working - #2 by zabaulkhan](https://forum.legato.io/t/start-up-scripts-not-working/2151/2)  
Thus in order to add init.d startup script, I have to rebuild Linux!?
