0

I'm trying to get a ruby script to run via cron. The cron job looks like this:

* * * * * /usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby /usr/share/adafruit/webide/repositories/shed_watcher/lib/shed_watcher.rb >> /tmp/cron_shed_watcher.log 2>&1 

I've encountered a couple of problems. The first was that the environment cron runs in could find one of the required gems:

require "rest_client" 

This was solved by setting the GEM_PATH in the crontab:

GEM_PATH=/usr/local/rvm/gems/ruby-2.0.0-p353:/usr/local/rvm/gems/ruby-2.0.0-p353@global 

The second problem is that the script, running on Occidentals on a Raspberry Pi, makes use of a temperature probe and needs to call:

`modprobe w1-gpio` `modprobe w1-therm` 

i.e. modprobe commands in backticks. Cron cannot execute this, instead I get an "operation not permitted" message. modprobe is found in /sbin so I added a path entry to my crontab:

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/usr/local/rvm/gems/ruby-2.0.0-p353/bin:/usr/local/rvm/gems/ruby-2.0.0-p353@global/bin:.... 

But I get the same error (not surprising as it was a "not permitted" message, not a "not found" message). What do I need to do to get this working?

2
  • What if you just added your modprobes to rc.local or similar to run it once at boot time. Commented Jan 12, 2014 at 12:06
  • That's a good idea, although I'd prefer the script to not rely on another file Commented Jan 12, 2014 at 12:27

1 Answer 1

1

You should add your job to the root's crontab, not the user's one. User's crontabs always executed with uid/gid of the user when root crontab can contain additional field:

* * * * * username /path/to/the/command 

Then command will be executed with username privileges/permissions.

4
  • Thanks, that worked although I didn't need to add a username Commented Jan 12, 2014 at 20:32
  • It works as root if no username placed, cause root hasn't restrictions. But for security reasons you have to set appropriate uid - possibly www. Commented Jan 12, 2014 at 21:37
  • Hmmm.... I didn't set a uid Commented Jan 13, 2014 at 0:08
  • Crontab owner always assumed when username omitted. Root can change to privileges to some other user while nonprivileged users can't. Commented Jan 13, 2014 at 10:21

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.