One of my main reasons for wanting an EC2 instance was to be able to automatically run scripts at certain times, normally to collect data and save it to a database. As my EC2 instance is always running, I can forget about it for a month and have a month’s worth of data ready and waiting.
Want to schedule scripts so that they automatically run at set times or at set intervals (e.g. every day at 1pm or every 10 minutes)? No problem, Crontab is the easy to use Linux scheduling program that allows such execution in a no-thrills, straightforward way.
The syntax works along the lines of:
<minute> <hour> <day of month> <month> <weekday> <task>
0 2 * * * python /location/of/script.py
will run script.py at 2am every day. Simples. (* is essentially a placeholder to say “do it for all integer values”)
To create or access your crontab, type crontab -e on the EC2 command line.
To see what’s scheduled by crontab, type crontab -l on the EC2 command line.