修改task.sh中参数名

This commit is contained in:
hanhh 2021-08-22 16:05:58 +08:00
parent bb4123805c
commit 1d4fec3979

View File

@ -7,14 +7,14 @@ dir_shell=/ql/shell
## 选择python3还是node ## 选择python3还是node
define_program() { define_program() {
local p1=$1 local first_param=$1
if [[ $p1 == *.js ]]; then if [[ $first_param == *.js ]]; then
which_program="node" which_program="node"
elif [[ $p1 == *.py ]]; then elif [[ $first_param == *.py ]]; then
which_program="python3" which_program="python3"
elif [[ $p1 == *.sh ]]; then elif [[ $first_param == *.sh ]]; then
which_program="bash" which_program="bash"
elif [[ $p1 == *.ts ]]; then elif [[ $first_param == *.ts ]]; then
which_program="ts-node-transpile-only" which_program="ts-node-transpile-only"
else else
which_program="" which_program=""
@ -75,23 +75,23 @@ run_nohup() {
## 正常运行单个脚本,$1传入参数 ## 正常运行单个脚本,$1传入参数
run_normal() { run_normal() {
local p1=$1 local first_param=$1
cd $dir_scripts cd $dir_scripts
define_program "$p1" define_program "$first_param"
if [[ $p1 == *.js ]]; then if [[ $first_param == *.js ]]; then
if [[ $# -eq 1 ]]; then if [[ $# -eq 1 ]]; then
random_delay random_delay
fi fi
fi fi
log_time=$(date "+%Y-%m-%d-%H-%M-%S") log_time=$(date "+%Y-%m-%d-%H-%M-%S")
log_dir_tmp="${p1##*/}" log_dir_tmp="${first_param##*/}"
log_dir="$dir_log/${log_dir_tmp%%.*}" log_dir="$dir_log/${log_dir_tmp%%.*}"
log_path="$log_dir/$log_time.log" log_path="$log_dir/$log_time.log"
cmd=">> $log_path" cmd=">> $log_path"
[[ "$show_log" == "true" ]] && cmd="" [[ "$show_log" == "true" ]] && cmd=""
make_dir "$log_dir" make_dir "$log_dir"
local id=$(cat $list_crontab_user | grep -E "$cmd_task $p1" | perl -pe "s|.*ID=(.*) $cmd_task $p1\.*|\1|" | head -1 | awk -F " " '{print $1}') local id=$(cat $list_crontab_user | grep -E "$cmd_task $first_param" | perl -pe "s|.*ID=(.*) $cmd_task $first_param\.*|\1|" | head -1 | awk -F " " '{print $1}')
local begin_time=$(date '+%Y-%m-%d %H:%M:%S') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
eval echo -e "## 开始执行... $begin_time\n" $cmd eval echo -e "## 开始执行... $begin_time\n" $cmd
eval cat $task_error_log_path $cmd eval cat $task_error_log_path $cmd
@ -99,7 +99,7 @@ run_normal() {
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path"
. $file_task_before $cmd 2>&1 . $file_task_before $cmd 2>&1
eval timeout -k 10s $command_timeout_time $which_program $p1 $cmd 2>&1 eval timeout -k 10s $command_timeout_time $which_program $first_param $cmd 2>&1
eval . $file_task_after $cmd 2>&1 eval . $file_task_after $cmd 2>&1
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
@ -110,37 +110,37 @@ run_normal() {
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行 ## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
run_concurrent() { run_concurrent() {
local p1=$1 local first_param=$1
local p3=$3 local third_param=$3
if [[ ! $p3 ]]; then if [[ ! $third_param ]]; then
echo -e "\n 缺少并发运行的环境变量参数" echo -e "\n 缺少并发运行的环境变量参数"
exit 1 exit 1
fi fi
cd $dir_scripts cd $dir_scripts
define_program "$p1" define_program "$first_param"
log_time=$(date "+%Y-%m-%d-%H-%M-%S") log_time=$(date "+%Y-%m-%d-%H-%M-%S")
log_dir_tmp="${p1##*/}" log_dir_tmp="${first_param##*/}"
log_dir="$dir_log/${log_dir_tmp%%.*}" log_dir="$dir_log/${log_dir_tmp%%.*}"
log_path="$log_dir/$log_time.log" log_path="$log_dir/$log_time.log"
cmd=">> $log_path" cmd=">> $log_path"
[[ "$show_log" == "true" ]] && cmd="" [[ "$show_log" == "true" ]] && cmd=""
make_dir $log_dir make_dir $log_dir
local id=$(cat $list_crontab_user | grep -E "$cmd_task $p1" | perl -pe "s|.*ID=(.*) $cmd_task $p1\.*|\1|" | head -1 | awk -F " " '{print $1}') local id=$(cat $list_crontab_user | grep -E "$cmd_task $first_param" | perl -pe "s|.*ID=(.*) $cmd_task $first_param\.*|\1|" | head -1 | awk -F " " '{print $1}')
local begin_time=$(date '+%Y-%m-%d %H:%M:%S') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
eval echo -e "## 开始执行... $begin_time\n" $cmd eval echo -e "## 开始执行... $begin_time\n" $cmd
eval cat $task_error_log_path $cmd eval cat $task_error_log_path $cmd
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path"
eval . $file_task_before $cmd 2>&1 eval . $file_task_before $cmd 2>&1
local envs=$(eval echo "\$${p3}") local envs=$(eval echo "\$${third_param}")
local array=($(echo $envs | sed 's/&/ /g')) local array=($(echo $envs | sed 's/&/ /g'))
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N") single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
for i in "${!array[@]}"; do for i in "${!array[@]}"; do
export ${p3}=${array[i]} export ${third_param}=${array[i]}
single_log_path="$log_dir/${single_log_time}_$((i + 1)).log" single_log_path="$log_dir/${single_log_time}_$((i + 1)).log"
timeout -k 10s $command_timeout_time $which_program $p1 &>$single_log_path 2>&1 & timeout -k 10s $command_timeout_time $which_program $first_param &>$single_log_path 2>&1 &
done done
wait wait
@ -167,7 +167,7 @@ run_else() {
[[ "$show_log" == "true" ]] && cmd="" [[ "$show_log" == "true" ]] && cmd=""
make_dir "$log_dir" make_dir "$log_dir"
local id=$(cat $list_crontab_user | grep -E "$cmd_task $p1" | perl -pe "s|.*ID=(.*) $cmd_task $p1\.*|\1|" | head -1 | awk -F " " '{print $1}') local id=$(cat $list_crontab_user | grep -E "$cmd_task $first_param" | perl -pe "s|.*ID=(.*) $cmd_task $first_param\.*|\1|" | head -1 | awk -F " " '{print $1}')
local begin_time=$(date '+%Y-%m-%d %H:%M:%S') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
eval echo -e "## 开始执行... $begin_time\n" $cmd eval echo -e "## 开始执行... $begin_time\n" $cmd
eval cat $task_error_log_path $cmd eval cat $task_error_log_path $cmd