How do I setup a cron job on OS X to run a curl command at a specific time every day?

I have a CURL command I want to run every day at say 3am, but I am not sure about how to set that up and the guides are all weird.

Assume I have a lot of terminal/bash experience, but I have never setup a cron before.

Is it possible for the cron job to wake up my computer, even if it is sleeping and the lid is closed (macbook pro), just to run this one curl command and then put it back to sleep?

How do I set it up either way?


Solution 1:

Start by running the command:

crontab -e

This will open up the crontab for your user in a text editor. Cron uses a specific notation for scheduled jobs. The format below shows the fields for a user crontab entry (which need to be separated by tabs).

min  hour  day_of_month  month  day_of_week  command

To schedule a curl command to run at 3am daily, you can insert the line:

0  3  *  *  *  curl args...

Notice how the minutes and hour correspond to 3am (side note: cron uses 24 hour time format, no am or pm). The asterisks that follow mean every day of month, every month, every day of week.

Cron will not be able to wake up your computer from sleep but you may find this post helpful crontab to wake osx from sleep