Automatically run shell script after booting



  • Hello,

    I want to run a shell script after booting openwrt by putting the script into the files folder so that when i build openwrt my scripts are automatically included in the build.

    I read that there is a folder called "files" in the root source openwrt build directory (~sourcce/files), anything placed in that folder will get included when you build openwrt.

    For example if you put a file in ~/source/files/etc it will appear in the /etc folder when you flash the binary to the onion device.

    So I tried that and it worked. The files do appear in there. So I read on this website:

    https://stackoverflow.com/questions/33340659/how-to-auto-start-an-application-in-openwrt

    That to get a script to run after boot up, I just need to put my script into /etc/init.d folder, then enable that script.

    But it seems if i try to type

    /etc/init.d/<your script> enable

    that enable function doesnt work in the onion openwrt docker for some reason.

    It gives an error that it cant open /etc/rc.common

    my script has execute permissions and has this in it:

     #!/bin/sh /etc/rc.common
     echo "hello"
    

    Does anyone know how to get a script to automatically run after booting openwrt, and have that script be apart of the build so that it automatically runs after boot after i flash it without having to type any other commands after flashing?

    Thanks



  • @nsmith your script echos the word hello, but where is it being echoed to? Since the script would be running in the background if it autostarts you can assume it would echo to the system log.

    You can add an entry to /etc/rc.local to tell the system to run your script on startup. The more accepted method is to create a proc.d script, take a look in /etc/init.d for some of the standard scripts so you can see how they work, also check Procd Documentation .

    Regarding adding script to your custom build, if you look under the source directory of your build system there is a subdirectory name "files", under this directory you can add files in the directory structure of yor live system and when you build and deploy your firmware these files will become part of your system. Also look at the uci-defaults subdirectory under files, these are scripts are used to set up the configuration etc for your custom firmware when it is deployed. Take a look at UCI Default Documentation for a complete description.


  • administrators

    @nsmith I suggest looking at this docs page as well: http://docs.onion.io/omega2-docs/running-a-command-on-boot.html



Looks like your connection to Community was lost, please wait while we try to reconnect.