Bash - Boot script - Run script on reboot (auto restart) or on a schedule
Edit to /etc/crontab
file.
sudo vim /etc/crontab
Add @reboot
followed by the user to run and the script.
@reboot ubuntu /home/ubuntu/my_script.sh
You can also add the above line into the crontab directory /etc/cron.d/
(do not use filename extension)
The following runs a script at the top of every hour.
sudo bash -c "echo '0 * * * * ubuntu /home/ubuntu/my_script.sh' > /etc/cron.d/myScript";