0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.