I am on Ubuntu 14.04 (using Digital Ocean) trying run a script as root. It's a script to check if a server is running and restart if it has crashed.
The issue isn't the script, but crontab won't run the script.
sudo crontab -e
#!/bin/bash
SHELL=/bin/bash
* * * * * /bin/bash /root/launch.sh
#newline-rwxr-xr-x 1 root root 845 Nov 23 06:21 launch.sh
Not sure what I'm doing incorrectly, other posts about crontabs have shown similar answers to this one.
11 Answer
I found an answer to my problem.
I added my bash commands to /etc/crontab and added the root field instead of using sudo crontab -e
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
* * * * * root bash /root/launch.sh