New on LowEndTalk? Please Register and read our Community Rules.
How to run a command on boot? CentOS and Ubuntu
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?
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.
@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.
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.