how to create a cron job to run a ruby script?

Check whenever(https://github.com/javan/whenever) gem to use cron jobs in Rails


If you are using RVM, you can simply do:

rvm cron setup 

Reference: https://coderwall.com/p/vhv8aw/getting-ruby-scripts-working-with-bundler-rvm-and-cron


If your ruby is in non standard paths then personally I like to wrap my ruby calls in a shell script, thereby ensuring that all the paths etc. my ruby program needs are set correctly, and schedule the script in crontab. Do something like

2 * * * * /home/mark/project/ruby_wrapper_sh >> /home/mark/cronOutput.txt 2>&1

and your /home/mark/project/ruby_wrapper_sh should read something like

#!/bin/bash

. ~mark/.bash_profile 
`ruby /home/mark/project/script.rb`