Reputation: 7451
I used crontab to run a bash script once a day (at midnight). This worked successfully, but I didn't really think it through enough to realise that the script would not run if my computer happened to be off at midnight (or even asleep).
So I think that I have to keep the crontab entry (in case my computer is on) but I also want to make the bash script execute on startup (in case my computer was off) so that I have covered all my bases.
I saw online that to have my script execute on startup I should edit my /etc/rc.local
file. My file now contains:
#! /bin/bash
bash /home/me/code.sh
exit 0
and my permissions are -rwxr-xr-x
.
However, the script does not execute on startup. Is there something I'm doing wrong?
Upvotes: 0
Views: 262
Reputation: 66
Anacron is the answer for your problem. This is cron like system created exactly for tasks on machines not always on. https://linux.die.net/man/5/anacrontab
Upvotes: 1
Reputation: 85
I guess you created the /etc/rc.local yourself right? AFAIK there isn't any in Ubuntu 18.04 anymore (as it is depricated). That's probably why it's not executed.
@reboot in crontab might be a possible solution for your problem.
Upvotes: 1