20

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?

22

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

  • 1
    When I do crontab -e I see this in my terminal: $ crontab -e crontab: no changes made to crontab, and then it opens my text editor with the file crontab.some-random-string from the folder /tmp. Once I edit that and save it, nothing happens in my terminal. If I do crontab -l, the job I just entered doesn't show up. Then if I do crontab -e again, it opens another blank crontab.some-random-string. I also tested the first crontab I saved by setting the time to be 2 mins from when I saved it and the cron never ran. What could be going on? – marcamillion Nov 21 '16 at 4:19
  • Which text editor is opening when you run 'crontab -e'? – diametralpitch Nov 21 '16 at 20:26
  • My default one, atom. That's what launches when I open anything to be edited in my terminal. This is what I have in my ~/.bash_profile, export EDITOR='open -a "/Applications/Atom.app"'. – marcamillion Nov 21 '16 at 23:07
  • Hmm, if you run atom from the command line on its own, does it wait for atom to exit before prompting for another command (if not, you may want to try a different text editor). – Adam Luchjenbroers Nov 23 '16 at 5:46
  • @AdamLuchjenbroers I am not sure I fully understand your question. I use atom for all of my code editing. So if I want to edit any file, I just do atom . inside the directory or atom <filepath>. – marcamillion Nov 23 '16 at 8:05
0

if you like to do it the GUI way i can recommend you CronniX from roaringapps https://roaringapps.com/app/cronnix

  • Thanks for that tip....but I think I would prefer doing it manually at the command line or via text editor to learn :) – marcamillion Nov 24 '16 at 2:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.