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?
system( cmd )
to correctly expand arguments. (Thesystem
forks a subshell)./#{path_to_pullLogs_sh} #{args}
)?args
and using./#{path_to_pullLogs_sh} #{year}#{month}#{day} 1 10
?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 notbash
.