From 63f21b16984ef1260cda94b155a3e08896f85401 Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Mon, 2 Aug 2021 18:57:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=9C=89=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E4=B8=AD=E6=96=AD=E7=9A=84tee?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/api.sh | 6 +++--- shell/task.sh | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/shell/api.sh b/shell/api.sh index a9ed9e06..98f9a186 100755 --- a/shell/api.sh +++ b/shell/api.sh @@ -170,10 +170,10 @@ update_cron() { code=$(echo $api | jq -r .code) message=$(echo $api | jq -r .message) if [[ $code == 200 ]]; then - echo -e "## 更新任务状态成功" | tee -p -a $log_path + echo -e "## 更新任务状态成功" >> $log_path else - echo -e "## 更新任务状态失败(${message})" | tee -p -a $log_path + echo -e "## 更新任务状态失败(${message})" >> $log_path fi } -get_token \ No newline at end of file +get_token diff --git a/shell/task.sh b/shell/task.sh index 359ba3e4..56b102b2 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -91,17 +91,17 @@ run_normal() { 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 begin_time=$(date '+%Y-%m-%d %H:%M:%S') - echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path + echo -e "## 开始执行... $begin_time\n" >> $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" . $file_task_before - timeout -k 10s $command_timeout_time $which_program $p1 2>&1 | tee -p -a $log_path + timeout -k 10s $command_timeout_time $which_program $p1 2>&1 >> $log_path . $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"))) - echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" | tee -p -a $log_path + echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" >> $log_path } ## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行 @@ -125,10 +125,10 @@ run_concurrent() { 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 begin_time=$(date '+%Y-%m-%d %H:%M:%S') - echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path + echo -e "## 开始执行... $begin_time\n" >> $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" . $file_task_before - echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n" | tee -p -a $log_path + echo -e "\n各账号间已经在后台开始并发执行,前台不输入日志,日志直接写入文件中。\n" >> $log_path single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N") for i in "${!array[@]}"; do @@ -141,7 +141,7 @@ run_concurrent() { [[ $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"))) - echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" | tee -p -a $log_path + echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" >> $log_path } ## 运行其他命令 @@ -154,17 +154,17 @@ run_else() { 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 begin_time=$(date '+%Y-%m-%d %H:%M:%S') - echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path + echo -e "## 开始执行... $begin_time\n" >> $log_path [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" . $file_task_before - timeout -k 10s $command_timeout_time "$@" 2>&1 | tee -p -a $log_path + timeout -k 10s $command_timeout_time "$@" 2>&1 >> $log_path . $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"))) - echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" | tee -p -a $log_path + echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" >> $log_path } ## 命令检测 @@ -191,6 +191,7 @@ main() { run_else "$@" ;; esac + cat $log_path elif [[ $# -eq 0 ]]; then echo usage