# 新增批量执行功能
run_batches() {
local accounts=()
# 读取所有 test-*.txt 文件的行
for file in test-*.txt; do
[ -f "$file" ] || continue
mapfile -t tmp < "$file"
for line in "${tmp[@]}"; do
[ -n "$line" ] && accounts+=("$line")
done
done
if [ ${#accounts[@]} -eq 0 ]; then
error "没有找到任何账号数据(xifan-*.txt)"
exit 1
fi
local total=${#accounts[@]}
local batch_size="${BATCH_SIZE:-10}"
local batch_delay="${BATCH_DELAY:-5}"
local start=0
local batch_num=1
log "分批处理模式:总共 $total 个账号,每批 $batch_size 个,批次间延迟 ${batch_delay} 秒"
while [ $start -lt $total ]; do
local end=$((start + batch_size))
[ $end -gt $total ] && end=$total
local batch=("${accounts[@]:$start:$((end - start))}")
# 用 /& 拼接(保留行内空格)
local joined
local IFS=$'/&'
joined="${batch[*]}"
export test_env="$joined"
log "执行第 $batch_num 批:账号 ${start} 到 $((end - 1)) / 共 $total"
run_program
start=$end
batch_num=$((batch_num + 1))
# 批次间延迟(最后一批不需要延迟)
if [ $start -lt $total ] && [ $batch_delay -gt 0 ]; then
log "等待 ${batch_delay} 秒后处理下一批..."
sleep "$batch_delay"
fi
done
}
版权归属:
管理员
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区