From 7ced425e01f4554e0a072de91761970ac08a5aa9 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Thu, 22 Jul 2021 19:13:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9task=5Fbefore=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/task.sh | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/shell/task.sh b/shell/task.sh index 263565d3..caff733e 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -93,19 +93,11 @@ run_normal() { local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" - if [[ ! $(. $file_task_before 1>/dev/null) ]]; then - . $file_task_before - else - echo -e "## task_before执行失败,自行检查\n" | tee -p -a $log_path - fi + . $file_task_before timeout -k 10s $command_timeout_time $which_program $p1 2>&1 | tee -p -a $log_path - if [[ ! $(. $file_task_after 1>/dev/null) ]]; then - . $file_task_after - else - echo -e "## task_after执行失败,自行检查\n" | tee -p -a $log_path - fi + . $file_task_after [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" local end_time=$(date '+%Y-%m-%d %H:%M:%S') local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) @@ -135,11 +127,7 @@ run_concurrent() { local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" - if [[ ! $(. $file_task_before 1>/dev/null) ]]; then - . $file_task_before - else - echo -e "## task_before执行失败,自行检查\n" | tee -p -a $log_path - fi + . $file_task_before echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n" | tee -p -a $log_path single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N") @@ -149,11 +137,7 @@ run_concurrent() { timeout -k 10s $command_timeout_time $which_program $p1 &>$single_log_path & done - if [[ ! $(. $file_task_after 1>/dev/null) ]]; then - . $file_task_after - else - echo -e "## task_after执行失败,自行检查\n" | tee -p -a $log_path - fi + . $file_task_after [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" local end_time=$(date '+%Y-%m-%d %H:%M:%S') local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) @@ -172,19 +156,11 @@ run_else() { local begin_time=$(date '+%Y-%m-%d %H:%M:%S') echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" - if [[ ! $(. $file_task_before 1>/dev/null) ]]; then - . $file_task_before - else - echo -e "## task_before执行失败,自行检查\n" | tee -p -a $log_path - fi + . $file_task_before - timeout -k 10s $command_timeout_time bash -c "$@" 2>&1 | tee -p -a $log_path + timeout -k 10s $command_timeout_time "$@" 2>&1 | tee -p -a $log_path - if [[ ! $(. $file_task_after 1>/dev/null) ]]; then - . $file_task_after - else - echo -e "## task_after执行失败,自行检查\n" | tee -p -a $log_path - fi + . $file_task_after [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" local end_time=$(date '+%Y-%m-%d %H:%M:%S') local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))