# Running script before applying an OTA update

**URL:** <https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299>\
**Category:** General Discussions\
**Created:** [August 10, 2020, 9:08am UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299 "2020-08-10T09:08:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamanRatna](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@SamanRatna](https://hub.mender.io/u/SamanRatna)\
**Post date:** [August 10, 2020, 9:08am UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/1 "2020-08-10T09:08:18Z")

</div>

Hi there,

I am having problem to run state scripts. I tried to run a sample script from location /var/lib/mender/scripts. But when I deploy the update, the update would run well and the script would not run at all and be deleted immediately. How do I run the script ?

Herewith, I have attached the script I am trying to test, and the log file of the deployment from my device.

 ![log4](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/ac07e3389da6745625fab371d2fab58890f769b3.png) ![script](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/f6c982ccbe9592826324422a32295536f91bd7aa.png)

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [August 10, 2020, 9:17am UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/2 "2020-08-10T09:17:16Z")

</div>

Hi 🙂

I will need a bit more information on what is going on, like the name of the script, and when you want it to run?  
Is this embedded in an Artifact, or did you manually add it to the script directory yourself?

See: [https://docs.mender.io/hosted/artifacts/state-scripts](https://docs.mender.io/hosted/artifacts/state-scripts) for further information

---

<div class="post-metadata">

**Author:** ![SamanRatna](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@SamanRatna](https://hub.mender.io/u/SamanRatna)\
**Post date:** [August 10, 2020, 9:34am UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/3 "2020-08-10T09:34:21Z")

</div>

Actually, I want to apply a User Confirmation use case for my project. I tried the directory update as shown in [State scripting for Raspberry PI board running ubuntu 18.04](https://hub.mender.io/t/state-scripting-for-raspberry-pi-board-running-ubuntu-18-04/1203/3) and [How to create state scripts with Mender using Raspberry Pi](https://hub.mender.io/t/how-to-create-state-scripts-with-mender-using-raspberry-pi/1518). Deployment would be successful but, the script wouldn’t run.

Is there specific way or location to save the script ?  
The -s prefix wouldn’t run with directory-artifact-gen and I tried it by modifying the code from [https://github.com/mendersoftware/mender/blob/master/support/modules-artifact-gen/directory-artifact-gen](https://github.com/mendersoftware/mender/blob/master/support/modules-artifact-gen/directory-artifact-gen)

![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/795e4b99f52dbe5763b5ea980602044624c2d6dc.png)

by adding -s ~/Downloads/ArtifactInstall\_Enter\_01\_User\_Confirmation-v2.py , but that didn’t work too.

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [August 10, 2020, 12:08pm UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/4 "2020-08-10T12:08:36Z")

</div>

Hi 🙂

It looks to me like you’re not using the generator though, but mender-artifact itself, in which case the `--` is not needed.

```auto
mendersoftware mender-artifact write module-image -T directory -s ArtifactInstall_Enter_01_User_Confirmation-v2.py -n foobar -t baz
mendersoftware mender-artifact read artifact.mender 
Mender artifact:
  Name: foobar
  Format: mender
  Version: 3
  Signature: no signature
  Compatible devices: '[baz]'
  Provides group: 
  Depends on one of artifact(s): []
  Depends on one of group(s): []
  State scripts:
    ArtifactInstall_Enter_01_User_Confirmation-v2.py

Updates:
    0:
    Type: directory
    Provides: Nothing
    Depends: Nothing
    Metadata: Nothing
    Files: None

```

works.

---

<div class="post-metadata">

**Author:** ![SamanRatna](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@SamanRatna](https://hub.mender.io/u/SamanRatna)\
**Post date:** [August 10, 2020, 3:03pm UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/5 "2020-08-10T15:03:32Z")

</div>

Hi there,

what is the mendersoftware there? is it smth to install separately ? Can you link me to something related to that ?

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [August 10, 2020, 3:09pm UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/6 "2020-08-10T15:09:30Z")

</div>

[https://docs.mender.io/hosted/downloads#mender-artifact](https://docs.mender.io/hosted/downloads#mender-artifact)

---

<div class="post-metadata">

**Author:** ![SamanRatna](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@SamanRatna](https://hub.mender.io/u/SamanRatna)\
**Post date:** [August 10, 2020, 3:12pm UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/7 "2020-08-10T15:12:26Z")

</div>

Hi,

I used the generator from here  
[https://github.com/mendersoftware/mender/blob/master/support/modules-artifact-gen/directory-artifact-gen](https://github.com/mendersoftware/mender/blob/master/support/modules-artifact-gen/directory-artifact-gen)

and made changes after line 163 as such

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/8d68a611437eba7918d365bdccfde4b8fe989dde.png)

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [August 10, 2020, 6:23pm UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/8 "2020-08-10T18:23:28Z")

</div>

You need to remove the “–” before the script option. That tells mender-artifact to stop processing command line parameters. I honestly don’t know what it will do in that case.

Also, the script you posted above is bash but you are using a .py extension. I don’t know if that will cause an issue or not.

Drew

---

<div class="post-metadata">

**Author:** ![SamanRatna](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@SamanRatna](https://hub.mender.io/u/SamanRatna)\
**Post date:** [August 12, 2020, 11:55am UTC](https://hub.mender.io/t/running-script-before-applying-an-ota-update/2299/9 "2020-08-12T11:55:42Z")

</div>

Thanks @drewmoseley
