How to run a shell script at startup

علی ذوالفقار
1399/03/09 22:55:19 (711)
create your script in /etc/init.d : 
	sudo nano /etc/init.d/NameOfYourScript

Make script executable
	sudo chmod 755 /etc/init.d/NameOfYourScript
    
Register script to be run at start-up : 
	sudo update-rc.d NameOfYourScript defaults
    
If you ever want to remove the script from start-up, run the following command :
	sudo update-rc.d -f  NameOfYourScript remove
    
or try this via Set a crontab for your .sh file (file must be executable) : 
	#crontab -e
	@reboot  /home/user/test.sh

i found this solution on stackoverflow too : Enter cron using sudo: sudo crontab -e Add a command to run upon start up, in this case a script: @reboot sh /home/user/test.sh Save: Press ESC then :x to save and exit, or hit ESC then ZZ (that's shift+zz) Run your test script without cron to make sure it actually works. Make sure you saved your command in cron, use sudo crontab -e Reboot the server to confirm it all works sudo @reboot
Back