I have a ruby script I want to execute every 10 minutes that I had working previously, but I lost my script and I’m trying to rewrite it and can’t get it to work. The cron settings I left unchanged from when it did work, but here’s what I have.
rvm_bin_path=/home/usr/.rvm/bin
GEM_HOME=/home/usr/.rvm/gems/ruby-1.9.3-p194
SHELL=/bin/bash
IRBRC=/home/usr/.rvm/rubies/ruby-1.9.3-p194/.irbrc
MY_RUBY_HOME=/home/usr/.rvm/rubies/ruby-1.9.3-p194
__array_start=0
rvm_path=/home/usr/.rvm
escape_flag=1
rvm_prefix=/home/usr
PATH=/home/usr/.rvm/gems/ruby-1.9.3-p194/bin:/home/usr/.rvm/gems/ruby-1.9.3-p194@global/bin:/home/usr/.rvm/rubies/ruby-1.9.3-p$
PWD=/etc
LANG=en_CA.UTF-8
_second=1
rvm_version=1.14.1 (stable)
_first=0
GEM_PATH=/home/usr/.rvm/gems/ruby-1.9.3-p194:/home/usr/.rvm/gems/ruby-1.9.3-p194@global
RUBY_VERSION=ruby-1.9.3-p194
_=/usr/bin/env
*/10 * * * * bash -li -c /home/usr/MeetCal-bot/run-bot.sh
I’m running cron as su, which is why I needed to add all those environment variables, to ensure it has everything it needs to run ruby. I had it working previously with all that same information, so I don’t think I’m missing anything
The bash script I have is this:
#!/bin/bash
ruby /home/usr/bot/bot.rb >> /home/usr/bot/output.txt
When the job runs, it makes output.txt, except it’s empty, and I would expect there to be some output, maybe a ruby error message.
I did chmod 777 * for the directory as a last resort, to try to fix any permissions issues, but that didn’t help.
If I run the ruby script as my local user, it runs fine without any errors, but I can’t seem to figure out why it works running as my user, but not as su.
I would leave out
-iand-c, since those aren’t necessary. Just dofor a start.
In your script, insert a
which ruby >>/home/usr/bot/output.txtto see, if it finds ruby at all. And to see any error messages, add2>&1to your ruby invocation