title: Run shell script on boot / start
body: <p>First of all , my rooted phone is Xiao Mi Red Mi Note 7.</p>
  
  <p>MIUI version : 10.2.3.</p>
  
  <p>Android Version : 9 PKQ1.180904.001.</p>
  
  <p><strong>Shell script :</strong></p>
  
  <pre><code>set -xeo pipefail
  
  _stopnow() {
    test -f stopnow &amp;&amp; echo "Stopping!" &amp;&amp; rm stopnow &amp;&amp; exit 0 || return 0
  }
  
  while true
  
  do
  
      _stopnow
  
      am instrument -w -r   -e debug false -e class com.package.mobile.name com.package.mobile.test/android.support.test.runner.AndroidJUnitRunner
  
  done
  
  </code></pre>
  
  <p><strong>What i have tried :</strong></p>
  
  <ol>
  <li>Use <a href="https://play.google.com/store/apps/details?id=os.tools.scriptmanager" rel="nofollow noreferrer">SManager</a> Version : 3.0.9</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/dDQX2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dDQX2.png" alt="enter image description here"></a></p>
  
  <p>Conclusion of this method : Killed</p>
  
  <ol start="2">
  <li>Use <strong>service.rc in /system/etc/init</strong></li>
  </ol>
  
  <p>Because i did not have /init.d folder i am using /init instead.</p>
  
  <p>I have file named <em>/system/etc/init/mypackagepipefail.rc</em> and <em>/system/bin/runpipefail</em></p>
  
  <p><strong>mypackagepipefail.rc</strong></p>
  
  <pre><code>on boot
      start /system/bin/runpipefail
      user system
      group system readproc
  </code></pre>
  
  <p><strong>runpipefail</strong></p>
  
  <pre><code>#!/bin/sh
  
  set -xeo pipefail
  
  _stopnow() {
    test -f stopnow &amp;&amp; echo "Stopping!" &amp;&amp; rm stopnow &amp;&amp; exit 0 || return 0
  }
  
  while true
  do
      _stopnow
      # Below here, you put in your command you want to run:
      am instrument -w -r   -e debug false -e class com.airasia.mobile.BigpayTest com.airasia.mobile.test/android.support.test.runner.AndroidJUnitRunner
  </code></pre>
  
  <p>Conclusion of this method : seems like service does not running on start / boot.</p>
  
  <p>Is there something wrong in usage of the service.rc above ?
  Is there any other method to run shell script on boot ?</p>
  
  <p>Any help would be so great.
  Thank you very much.</p>