开发者

how to invoke ruby script containing system command with cron job?

开发者 https://www.devze.com 2022-12-11 07:35 出处:网络
I have a ruby script containing system command like http://gist.github.com/235833, while I ran开发者_JAVA技巧 this script from shell, it works correctly, but when I added it to my cron job list, it do

I have a ruby script containing system command like http://gist.github.com/235833, while I ran开发者_JAVA技巧 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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消