Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a cron job that will run everyday at 12:20am?

I am trying to write a cron job on my Mac OS X machine that will run a Ruby script at 12:20am everyday.

This is what I need to run but I don't know the syntax or the command to use on the Mac:

/usr/bin/ruby /Users/tamer/scripts/sftp.rb

I read about doing crontab -e but do I need to do something afterwards?

like image 803
Matt Elhotiby Avatar asked Sep 06 '11 21:09

Matt Elhotiby


People also ask

How do I schedule a cron job every 12 hours?

Show activity on this post. ->cron('0 */12 * * *'); This cron will run the scheduler at every 12 hours.

How do I schedule a cron job every 10 minutes?

For example, if you have 1-10/2 in the Minutes field, it means the action will be performed every two minutes in range 1-10, same as specifying 1,3,5,7,9 . Instead of a range of values, you can also use the asterisk operator. To specify a job to be run every 20 minutes, you can use “*/20”.


2 Answers

The crontab for "everyday at 12:20am" is

20 0 * * *

The whole line in crontab would then be

20 0 * * * /usr/bin/ruby /Users/tamer/scripts/sftp.rb
like image 117
Bohemian Avatar answered Sep 24 '22 11:09

Bohemian


The crontab entry should look like:

20 0 * * * /usr/bin/ruby /Users/tamer/scripts/sftp.rb

This assumes that you don't need any other environment variables to make it all work. If you do need other variables, then create an environment-setting shell script which then executes the Ruby program and script.

To submit the job, I usually use:

crontab -l > x3
echo  "20 0 * * * /usr/bin/ruby /Users/tamer/scripts/sftp.rb" >> x3
crontab < x3
rm x3
like image 40
Jonathan Leffler Avatar answered Sep 22 '22 11:09

Jonathan Leffler