尝试用警告运行代码和调试启用:
ruby -cW2 path/to/your/code
你应该看到:
syntax error, unexpected tIDENTIFIER, expecting keyword_end
... sleep(10)
... ^
你需要做这个作为第一STE当你遇到问题时。在启用警告并将其设置为最高值时,Ruby会为您提供有关脚本问题的更多详细信息。下面介绍一下标志的含义:
-c check syntax only
-W[level=2] set warning level; 0=silence, 1=medium, 2=verbose
你得到这个错误,因为sleep(10)
需要作为一个单独的语句执行。您可以在其间插入;
,并调用cURL,或将其放在一行上。为了使命令更易于阅读,我建议使用第二个选项。
此外,我强烈建议使用Curb gem,而不是像你一样在子shell中启动cURL。你正在失去灵活性,浪费CPU时间,然后在操作系统上创建一个新的shell来启动cURL。最后,您需要学习更清晰地编写代码,否则您很快就会陷入困惑的角落。下面是我怎么会写代码的起点:
require 'uri'
@array_timestampdate = ['start_date', 'end_date']
(1..180000).step(20000) do |userb|
(20000..180000).step(20000) do |usere|
uri = URI.parse('http://XXXXX/scripts/exportStatsCsv/testA1')
uri.query = URI.encode_www_form(
{
'start' => userb,
'end' => usere,
'startDate' => @array_timestampdate[0],
'endDate' => @array_timestampdate[1]
}
)
curl = %Q[ curl -i -s -H "Host: xxxx" "#{uri.to_s}" ]
puts curl
end
end
随着输出的一个小例子:
>> curl -i -s -H "Host: xxxx" "http://XXXXX/scripts/exportStatsCsv/testA1?start=1&end=20000&startDate=start_date&endDate=end_date"
...
>> curl -i -s -H "Host: xxxx" "http://XXXXX/scripts/exportStatsCsv/testA1?start=160001&end=180000&startDate=start_date&endDate=end_date"
定义“什么也没有”。 –