How to Run a Linux Script During Reboot or Startup

I come across one use case where I need to run a Linux script during reboot or startup of the system.

To handle this use-case I have created new script in /etc/init.d/myscript.

Lets consider the below example script.

/etc/init.d/myscript

#! /bin/sh

### BEGIN INIT INFO
# Provides:          myupdate
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
    start)
        /path/to/update/script
        ;;
    stop|restart|reload)
        ;;
esac

Make it executable.

chmod ugo+x /etc/init.d/myscript

Configure the init system to run this script at startup.

update-rc.d myscript defaults

Once you activated myscript using update-rc.d then the start action will be executed upon boot

Few more related Reference

https://github.com/roopendra/devops/tree/master/bash_scripting

(Visited 177 times, 4 visits today)