Execute Bash script at startup, but only once a day?

I have a bash script that should be executed on ubuntu startup after boot.

The problem is the script should be only executed once a day. So when the script recognizes that it already has been executed today it should stop itself. How can i do this?


As Ubuntu uses Anacron by default, you already have this behaviour by putting the script into /etc/cron.daily. Check run-parts --test /etc/cron.daily to check if your script is picked up (importantly, no .sh extension and the +x bit set). See this wiki page and man anacron for more detailed information about why this will work for you.


If you have a desktop it's easy to do using the GUI: howtogeek article.

If you have a headless server then Iain Lane's answer should be good enough but you could also edit /etc/rc.local just make sure your script ends with exit 0. rc.local is the "preferred" place for startup scripts but cron daily works just fine. Use crontab -e to edit your own crontab file. Here is a nice little Howto on using cron.