S3Sync.net
February 02, 2014, 01:31:48 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Ruby script fails if called by cron (but works in shell)  (Read 3430 times)
insane85
Newbie
*
Posts: 4


View Profile WWW
« on: March 18, 2009, 03:21:33 PM »

Hi,
I have a bash script that I want to run every week (backup_dati.sh).
The script do something like that (but a bit more complex):

Code:
mkdir /usr/emanuele/s3sync/archivi/dati/officineparon.com

tar -czf - "/var/www/vhosts/officineparon.com" | split -b 4m - "/usr/emanuele/s3sync/archivi/dati/officineparon.com/officineparon.com.tar.gz"

/usr/emanuele/s3sync/s3sync.rb -r "/usr/emanuele/s3sync/archivi dati/officineparon.com/" backup-server-integramenti1:backup-
dati/officineparon.com/

rm -f -r /usr/emanuele/s3sync/archivi/dati/officineparon.com



It works if I run from shell:
sh /usr/emanuele/s3sync/script/backup_dati.sh

but if I setup a cronjob, the 3rd line (where I call the ruby script) is skipped.
I try to edit main cron with:

crontab -e

and also with:

vi /etc/crontab

adding the line

3 19 18 3 * root sh /usr/emanuele/s3sync/script/test.sh



Then I tried to modify the line in:
Code:
ruby /usr/emanuele/s3sync/s3sync.rb -r -v "/usr/emanuele/s3sync/archivi/dati/officineparon.com/" backup-server-integramenti1:backup-dati/officineparon.com/ >> "/usr/emanuele/s3sync/archivi/log/backup_test_log2.html"

but the result is the same...

"tar" instruction works ok, ruby not....someone knows why?!
I must configure something?


thanks...
Logged
assettv
Newbie
*
Posts: 2


View Profile
« Reply #1 on: March 19, 2009, 03:42:26 AM »

This is going to be due the difference in your environment. Cron has a pretty empty environment by default.

Best thing to do is type "set" on the command line and add "set" to the script and compare the two. There will be one or more values missing from the cron environment which will need adding in the script (export xxx=yyy)
Logged
insane85
Newbie
*
Posts: 4


View Profile WWW
« Reply #2 on: March 19, 2009, 08:54:41 AM »

yesssss! it works now!  Wink

I've compared the "set" outputs from shell and cron and in shell I have this intereresting line:
Code:
S3CONF=/usr/emanuele/s3sync

the only thing I've done is adding a line on the beginning of my bash script:
Code:
export S3CONF=/usr/emanuele/s3sync

and now it's ok

thanks for your help!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!