How to run a shell script at startup

meetamit picture meetamit · Oct 19, 2012 · Viewed 1.1M times · Source

On an Amazon S3 Linux instance, I have two scripts called start_my_app and stop_my_app which start and stop forever (which in turn runs my Node.js application). I use these scripts to manually start and stop my Node.js application. So far so good.

My problem: I also want to set it up such that start_my_app is run whenever the system boots up. I know that I need to add a file inside init.d and I know how to symlink it to the proper directory within rc.d, but I can't figure out what actually needs to go inside the file that I place in init.d. I'm thinking it should be just one line, like, start_my_app, but that hasn't been working for me.

Answer

Hemant kumar picture Hemant kumar · Mar 25, 2015

Set a crontab for this

#crontab -e
@reboot  /home/user/test.sh

after every startup it will run the test script.