I want to create a cron job to run a ruby script. this is what i have put in the crontab.
2 * * * * ruby /home/mark/project/script.rb >> /home/mark/cronOutput.txt
But its not running. I think there's some problem with the environment getting loaded up when the cron runs as root.
Please help.
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`
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