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
For some people, this will work:
You could simply add the following command into System → Preferences → Startup Applications:
bash /full/path/to/your/script.sh
Just have a line added to your crontab..
Make sure the file is executable:
chmod +x /path_to_you_file/your_file
To edit crontab file:
crontab -e
Line you have to add:
@reboot /path_to_you_file/your_file
That simple!
For Debian 9 see https://askubuntu.com/questions/228304/how-do-i-run-a-script-at-start-up. It is helped me. Short version for Debian 9: add commands (as root) to /etc/rc.local
/path_to_file/filename.sh || exit 1 # Added by me
exit 0
Probably, /path_to_file/filename.sh should be executable (I think so).
Set a crontab for this
#crontab -e
@reboot /home/user/test.sh
after every startup it will run the test script.
This simple solution worked for me on an Amazon Linux instance running CentOS.
Edit your /etc/rc.d/rc.local
file and put the command there. It is mentioned in this file that it will be executed after all other init scripts. So be careful in that regards. This is how the file looks for me currently.. Last line is the name of my script.
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)
Test Test Test:
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