Asyncronous Cron Jobs on Linux
Cron jobs are nice, but what about when your machine is off? Perhaps you want to run a task daily/weekly/monthly and run it right away after you boot if it is due. We can do this with anacron.
On Arch Linux install the cronie package:
yay -S cronie
In this example I'll use a Python script update.py, but you could use a shell/bash script instead.
Check your active Python environment:
which python3
/path/to/your/python/env/bin/python3
Edit update.py
vi /path/to/your/python/script/update.py
Put this at the top of the file:
#!/path/to/your/python/env/bin/python3
Make your python script executable:
chmod +x /path/to/your/python/script/update.py
I want to run this update script daily so I shall make a symbolic link in /etc/cron.daily:
sudo ln -s /path/to/your/python/script/update.py /etc/cron.daily/update
That's it, my machine will now update once daily and will update if it is due after booting.