From 5395cebdb436b34587a80c1330ad77f45737f279 Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 1 Sep 2023 22:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E6=9C=89=E7=A9=BA=E6=A0=BC=E6=97=B6=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/api.sh | 2 +- shell/otask.sh | 30 +++++++++++++++++++----------- shell/task.sh | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/shell/api.sh b/shell/api.sh index ea88f29c..a7128726 100755 --- a/shell/api.sh +++ b/shell/api.sh @@ -36,7 +36,7 @@ add_cron_api() { local sub_id="$4" fi - if [[ ! $sub_id ]];then + if [[ ! $sub_id ]]; then sub_id="null" fi diff --git a/shell/otask.sh b/shell/otask.sh index 9ee3dafb..72166ad4 100755 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -86,6 +86,11 @@ check_server() { fi } +env_str_to_array() { + local IFS="&" + read -ra array <<<"${!env_param}" +} + ## 正常运行单个脚本,$1:传入参数 run_normal() { local file_param=$1 @@ -113,8 +118,7 @@ run_concurrent() { exit 1 fi - local envs=$(eval echo "\$${env_param}") - local array=($(echo $envs | sed 's/&/ /g')) + env_str_to_array local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") local runArr=($(eval echo $tempArr)) runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]})) @@ -125,11 +129,13 @@ run_concurrent() { let n++ done - local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g') - [[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr} + local cookieStr=$( + IFS="&" + echo "${array_run[*]}" + ) + [[ ! -z $cookieStr ]] && export "${env_param}=${cookieStr}" - local envs=$(eval echo "\$${env_param}") - local array=($(echo $envs | sed 's/&/ /g')) + env_str_to_array single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%3N") cd $dir_scripts @@ -139,7 +145,7 @@ run_concurrent() { file_param=${file_param/$relative_path\//} fi for i in "${!array[@]}"; do - export ${env_param}=${array[i]} + export "${env_param}=${array[i]}" single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log" eval $timeoutCmd $which_program $file_param &>$single_log_path & done @@ -161,8 +167,7 @@ run_designated() { exit 1 fi - local envs=$(eval echo "\$${env_param}") - local array=($(echo $envs | sed 's/&/ /g')) + env_str_to_array local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") local runArr=($(eval echo $tempArr)) runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]})) @@ -173,8 +178,11 @@ run_designated() { let n++ done - local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g') - [[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr} + local cookieStr=$( + IFS="&" + echo "${array_run[*]}" + ) + [[ ! -z $cookieStr ]] && export "${env_param}=${cookieStr}" cd $dir_scripts local relative_path="${file_param%/*}" diff --git a/shell/task.sh b/shell/task.sh index 17bd5d41..52445b51 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -69,7 +69,7 @@ handle_log_path() { if [[ $real_log_path ]]; then log_path="$real_log_path" fi - + cmd=">> $dir_log/$log_path 2>&1" make_dir "$dir_log/$log_dir" if [[ "$show_log" == "true" ]]; then