Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

How to run a command on boot? CentOS and Ubuntu

JokerJoker Member

I have a .sh file that need to be run every time after restarting OS so is there a way to make it possible on every start up instead of me running the file through command line each time i restart the VPS?

current command i use is: (after getting into that folder)

./myfile.sh run

how can i make it automatic so with every restart it runs automatically?

Comments

  • you restart so very often? lol

    how bout chkconfig?

  • JokerJoker Member

    Yes i restart very often and i don't want to run the command every time lol i am a bit lazy

  • http://lmgtfy.com/?q=rc.local is what you're looking for.

  • JokerJoker Member

    @stackmutt thanks can i use rc.local to stop the script before shutdown as well? or there is no chance of getting my app file or database corrupt if i shutdown/restart it before running the stop command.

    for stop i use:

    ./myfile.sh stop

  • afaik you'll need to go the chkconfig or the like route if you want 'proper' behaviour.

  • AeneAene Member

    What about adding:

    @reboot /path/to/script.h

    to your crontab?

  • Or what about
    mv script.sh /etc/init.d/script chmod 755 /etc/init.d/script update-rc.d script defaults

    This should run the script on every system startup.

Sign In or Register to comment.