Search code examples
bashshellcommand-lineraspberry-piraspbian

How could I run a shell script with delay


I basically want to run a script which is a server but with 10 second delay, it is because I need some stuff to run before this script.

The server is located in the folder /etc/init.d but basically to make it work I go to that path using the command line and I have to restart the server typing:

sudo ./znodejs.sh stop

And then I start the server again:

sudo ./znodejs.sh start

I would like to know if there is any way to run those commands with a delay.


Solution

  • In order to make a script run on startup first make it executable:

    $ sudo chmod 755 /etc/init.d/znodejs.sh
    

    Then you can register the script to be run at startup:

    $ sudo update-rc.d znodejs.sh defaults
    

    (Edit) original answer:

    the sleep command sill pause for a given number of seconds:

    sudo ./znodejs.sh stop
    sleep 10
    sudo ./znodejs.sh start