tags:

views:

240

answers:

3

I have a ruby script containing system command like http://gist.github.com/235833, while I ran this script from shell, it works correctly, but when I added it to my cron job list, it doesn't work any more, the cron job is like:

10/* * * * * cd /home/hekin; /usr/bin/ruby my_script.rb

any idea what's going wrong with what i've done? Thank you.

A: 

Try to separate the things that might go wrong. The ones I can think of are:

  • The cron syntax - is the time value given legal and fitting your shell?
  • Permissions - execute permissions and read permissions for the relevant directory and file
  • Quoting - what scope does cron cover? Does it run only the first command?

In order to dissect this, I suggest you first run a really simple cron job, like 'ls'. Next run a single-liner script. Next embed your commands in a shell-script file. Somewhere along these lines you should find the problem.

Yuval F
@Yuval, I've tried all of the 3 items you mentioned, no luck, but thank you anyway, impressive
leomayleomay
A: 

The problem is your environment. While testing in your shell its fully equipped and boosted by your shell environment. While running under cron its very, very stripped down.

Where is the destination "." for your script? I guess it will be "/" and may not "$HOME" thus your script won't be able to write at that location and fails. Try using an absolut path for the destination.

Comradin
@Comradin, the absolute path doesn't work. And worse, I don't know the where the error message is.
leomayleomay
Comradin
+1  A: 

Hey, guys,

Thank you all for your answers.

It's my mistake.

Since I'm using ssh key forwarding on the local machine, while I executed the script from the shell, the ssh key forwarding related environment variables are all sitting there, but from cron job context, those environment variables are missing.

leomayleomay