Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a Ruby script that orchestrates a number of other scripts. One of the bash scripts pulls log data from a server, and a ruby script then parses them.

My bash script looks something like this:

#pullLogs.sh
for ((x = $2; x <= $3; x++)); do
    # creates a subdirectory for each server number
    rsync --progress -rvze ssh name@$ARCHIVE_SERVER:/path/to/log/$logDate.gz $x/
done
for ((x = $2; x <= $3; x++)); do
     cd $x
     for z in *.gz; do gunzip $z; done
     cd ..
done
cd ..

What this script does is pulls logs from a given date, from specified servers. Usually there are ten servers, so the script will pull from server 1, then from server 2, etc etc.

This script works perfectly if I specify the desired date from the command line

./pullLogs.sh desired_date 1 10

successfully pulls all the logs from the desired date from all ten servers.

However, I want to pull all the logs from todays date to some past date, and parse each one. So I use this ruby script:

while upload_day != $DESIRED_DATE do
    args = "#{year}#{month}#{day} 1 10"
    `./#{path_to_pullLogs_sh} #{args}`
    `ruby #{name_of_followup_ruby_script}`
    upload_day = upload_day.prev_day 
end

The ruby script iterates through the correct days and calls the correct bash script (the one given above). However, after running the bash script, it produces an error:

./pullLogs.sh: 15: ./pullLogs.sh: Syntax error: Bad for loop variable

So when I run it from the console, the loop variables 1 and 10 are good, but when I run it from the ruby script, it does not interpret the loop variables as acceptable.

How can make this work?

share|improve this question
    
try to use system( cmd ) to correctly expand arguments. (The system forks a subshell) –  jm666 Aug 5 at 20:17
    
Do I still use the backticks? That is, can I use system(./#{path_to_pullLogs_sh} #{args})? –  johncorser Aug 5 at 20:19
    
It still fails when I use system( "./"+path_to_pullLogs_sh + " " + args ) What is the exact command that will resolve the bad for loop error? –  johncorser Aug 5 at 20:25
    
Have you tried getting rid of args and using ./#{path_to_pullLogs_sh} #{year}#{month}#{day} 1 10? –  thankyour Aug 5 at 21:00
1  
That is a dash error message. You aren't specifying the shell to use and ruby is, apparently, falling back to /bin/sh which on your system is not bash. –  Etan Reisner Aug 5 at 21:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.