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