[ACCEPTED]-how to create a cron job to run a ruby script?-crontab
If your ruby is in non standard paths then 6 personally I like to wrap my ruby calls 5 in a shell script, thereby ensuring that 4 all the paths etc. my ruby program needs 3 are set correctly, and schedule the script 2 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 1 should read something like
#!/bin/bash . ~mark/.bash_profile `ruby /home/mark/project/script.rb`
If you are using RVM, you can simply do:
rvm cron setup
Check whenever(https://github.com/javan/whenever) gem to use cron jobs in 1 Rails
working on centos
in your terminal execute
# which ruby which is find 7 your ruby path
Then you can 6 edit your cronjob, using crontab -e
* * * * * /usr/bin/ruby /home/mark/project/script.rb
and save, this 5 simply working on my centos server. You 4 can test the code first using this command 3 before you edit your cronjob
it should be 2 working first, then you can put on your 1 crontab
Thanks for @saihgala for his solution, but 4 I'm little modified this way.
#!/usr/bin/env ruby sting 3 to the beginning of my ruby executable file.
Add 2 permissions for this file, launch crontab 1 file edit
*/1 * * * 0-5 /path/to/executable.rb>>/path/to/output.txt and then it works for me.
More Related questions