从Ruby运行bash脚本:“quot;循环变量“坏”;错误
我有一个Ruby脚本,它协调了许多其他脚本。其中一个bash脚本从服务器提取日志数据,然后一个ruby脚本解析它们 我的bash脚本如下所示:从Ruby运行bash脚本:“quot;循环变量“坏”;错误,ruby,linux,bash,shell,Ruby,Linux,Bash,Shell,我有一个Ruby脚本,它协调了许多其他脚本。其中一个bash脚本从服务器提取日志数据,然后一个ruby脚本解析它们 我的bash脚本如下所示: #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
#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 ..
成功地从所有十台服务器中提取所需日期的所有日志
但是,我想将所有日志从今天的日期拉到过去的某个日期,并解析每个日志。所以我使用这个ruby脚本:
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
ruby脚本在正确的日期内迭代并调用正确的bash脚本(上面给出的脚本)。但是,在运行bash脚本后,它会产生一个错误:
./pullLogs.sh: 15: ./pullLogs.sh: Syntax error: Bad for loop variable
因此,当我从控制台运行它时,循环变量1和10是好的,但是当我从ruby脚本运行它时,它不会将循环变量解释为可接受的
如何使其工作?尝试使用
system(cmd)
正确展开参数。(系统分叉一个子shell)我仍然使用backticks吗?也就是说,我可以使用system(/#{path_to_pullLogs_sh}{code>)吗?当我使用system(“./”+path_to_pullLogs_sh+”+args)时,它仍然会失败。解决坏for循环错误的确切命令是什么?您是否尝试过摆脱args
,并使用/#path_to_pullLogs_sh}年{月}{1 10
?这是一条破折号
错误消息。您没有指定要使用的shell,而ruby显然又回到了/bin/sh
,这在您的系统上不是bash
。
./pullLogs.sh: 15: ./pullLogs.sh: Syntax error: Bad for loop variable