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?
Show activity on this post. ->cron('0 */12 * * *'); This cron will run the scheduler at every 12 hours.
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”.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With