WebFaction
Community site: login faq

I want to run a ruby script with crontab, here the bash script:

#!/bin/bash -
export GEM_HOME="$PWD/.gems"
export RUBYLIB="$PWD/.gems/lib"
export PATH="$PWD/.gems/bin:$PATH"
"/usr/local/bin/ruby1.9" $PWD/rdog.rb

give this error:

 (LoadError)in/ruby1.9: No such file or directory -- /home/{username}/watchdog-ruby/rdog.rb

when lauche manually its everything ok ....

This question is marked "community wiki".

asked 18 Sep '13, 05:15

ApeBox
112
accept rate: 0%


Hello,

You need to remember that commands launched from 'cron' have a completely blank environment (so things like $PATH will be undefined). Also, you can't assume what your current working directory is, so things like $PWD probably won't work as expected.

I suggest that you use absolute paths for ALL values in your script.

Also, check this out for a super elegant way to debug these types of situations: http://benohead.com/linux-simulate-the-cron-environment-to-test-run-your-scripts/

Let me know if you have further questions.

~Christopher S, WebFaction Support

permanent link

answered 18 Sep '13, 12:55

likebike
3366
accept rate: 28%

edited 18 Sep '13, 12:56

After further investigation seems the problem it's not crontab, even when launched directly the error pop up.

start.sh:

export GEM_HOME="/home/{username}/watchdog-ruby/.gems"
export RUBYLIB="/home/{username}/watchdog-ruby/.gems/lib"
export PATH="/home/{username}/watchdog-ruby/.gems/bin:$PATH"
/usr/local/bin/ruby1.9 /home/{username}/watchdog-ruby/rdog.rb

launched with

sh start.sh

return " (LoadError)in/ruby1.9: No such file or directory -- /home/{username}/watchdog-ruby/rdog.rb"

while doing it manually (setting up the env) run smoothly ....

what i am missing ?

(19 Sep '13, 03:33) ApeBox

This is gettin weird... even a simple:

/bin/ls $HOME

is givin

": No such file or directorye/{username}"

but

/bin/echo $HOME

show that $HOME is correct ... i am really not understanding what is happening !

(19 Sep '13, 03:57) ApeBox

One support guy helped me finding the problem: LINE ENDINGS ... i was using Putty from a Windows and didn't realize this was a problem.

They converted the shell script with dos2unix and everything went right !

permanent link
This answer is marked "community wiki".

answered 19 Sep '13, 04:15

ApeBox
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×81
×81
×23
×11

question asked: 18 Sep '13, 05:15

question was seen: 3,373 times

last updated: 19 Sep '13, 04:15

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM