Search code examples
pythonamazon-web-servicesamazon-ec2cron

crontab in ubuntu (AWS)


I recently learned that cron jobs in Mac OS terminal will not run if the computer is off/asleep.

I had always assumed that cron jobs run regardless of whether the machine is on or off.

I have a crontab (with a couple python scripts) on linux (ubuntu) that is running on AWS (an EC2 instance). Will my cron jobs will run regardless of whether my computer is on or off? I've always thought yes, because the crontab is running on the cloud (AWS) and not my local machine. But now I'm not so sure.


Solution

  • Yes, contab jobs should run if the computer their setup on is running.

    If you SSH from your laptop into a VM and setup a crontab job on the VM properly then it should run as long as the VM is on and running even if your laptop is off.

    You should be able to test this using a simple script that creates a file (or something similar) set to 5 minutes in the future then quickly turn off your laptop and check again in 10 minutes. If you have things setup correctly then when you check the script will have created the file (or whatever you set it to do). If this works then you can continue confidently. If it doesn't work (the file didn't appear) then something is wrong with how the crontab job was set up.