我有一个python脚本,用于从服务器收集数据。我可以把它当作:
./ApiStreamingClient.py -w flow-index -n admin -p admin localhost 1477389500000000000 1477389900000000000 | gzip - > out.gz
其中1477389500000000000
和1477389900000000000
是定义间隔的纳秒时间。
由于服务很慢,我需要编写一个在子区间中运行相同代码的bash脚本。
这是我目前的尝试,但编译时出现了一些错误:
#!/bin/bash
file_name=$1
data_type=$2
username=$3
password=$4
address=$5
start_time=$6
end_time=$7
set batch_size = 1000000000
set batch_start = start_time
set batch_end = current_time + batch_size
while (("$batch_end" < "$end_time"))
do
echo "iteration $i batch_start=$batch_start batch_end=$batch_end"
./$file_name -w flow-index -n $username -p $password $address $batch_start $batch_end | gzip > "out
set /a batch_start = batch_end + 1
set /a batch_end = batch_start + batch_size
done
~
我认为错误在于如何定义while循环以及如何更新batch_start
和batch_end
变量。
你能解释一下这段代码有什么问题吗?我的知识o bash接近0,我想有脚本的工作版本和问题的解释。
Thansk!
编辑: 我仍然会遇到错误:
#!/bin/bash
file_name=$1
data_type=$2
username=$3
password=$4
address=$5
start_time=$6
end_time=$7
batch_size = 1000000000
batch_start = $start_time
batch_end = $((current_time + batch_size))
while (("$batch_end" < "$end_time$))
do
echo "iteration $i batch_start=$batch_start batch_end=$batch_end"
./$file_name -w flow-index -n $username -p $password $address $batch_start $batch_end | gzip > "out_$i.gz"
batch_start =$((batch_end + 1))
batch_end =$((batch_start + batch_size))
done
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
probe27:/data/misc #
probe27:/data/misc #
probe27:/data/misc #
probe27:/data/misc #
probe27:/data/misc # sh GetStreamingFlowData.sh ApiStreamingClient.py -w flow-index -n admin -p admin localhost 1477389500000000000 1477389900000000000
GetStreamingFlowData.sh: line 11: batch_size: command not found
GetStreamingFlowData.sh: line 12: batch_start: command not found
GetStreamingFlowData.sh: line 13: batch_end: command not found
GetStreamingFlowData.sh: line 20: unexpected EOF while looking for matching `"'
GetStreamingFlowData.sh: line 24: syntax error: unexpected end of file
probe27:/data/misc #
答案 0 :(得分:0)
这是seq
的作业:
start=1477389500000000000
end=1477389900000000000
step=1000000000
for current_step in $(seq $start $step $end); do
echo $current_step
done
答案 1 :(得分:0)
您具有将值赋值给错误的语法。您正在编写 bash
脚本,而不是DOS batch
文件。
#!/bin/bash
file_name=$1
data_type=$2
username=$3
password=$4
address=$5
start_time=$6
end_time=$7
batch_size=1000000000
batch_start=$start_time
batch_end=$((current_time + batch_size))
while (("$batch_end" < "$end_time"))
do
echo "iteration $i batch_start=$batch_start batch_end=$batch_end"
./$file_name -w flow-index -n "$username" -p "$password" "$address" "$batch_start" "$batch_end" | gzip -c > out
batch_start=$((batch_end + 1))
batch_end=$((batch_start + batch_size))
done