From 78f643c50fe93eb2cf3e5c611f29d0517863e359 Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 1 Oct 2022 23:12:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=ACv2.14.7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/task.sh | 46 ++++++++++++++-------------------------------- src/version.ts | 12 +++++------- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/shell/task.sh b/shell/task.sh index c754c88d..4c2230b8 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -129,15 +129,8 @@ check_server() { # eval echo -e "\#\# 当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \\\n" $cmd if [[ $cpu_use -gt $cpu_warn ]] || [[ $mem_free -lt $mem_warn ]] || [[ $disk_use -gt $disk_warn ]]; then - # echo -e "\#\# 服务器资源占用异常,本次任务跳过执行" $cmd - local resource = $(top -b -n 1 | grep -v -E 'grep|Mem|idle|Load' | awk '{$2="";$3="";$4="";$5="";$7="";print $0}' | head -n 10) + local resource = $(top -b -n 1 | grep -v -E 'grep|Mem|idle|Load' | awk '{$2="";$3="";$4="";$5="";$7="";print $0}' | head -n 10) notify_api "服务器资源异常警告" "当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \n资源占用详情 \n\n $resource" - - # end_time=$(date '+%Y-%m-%d %H:%M:%S') - # diff_time=$(($end_timestamp - $begin_timestamp)) - # [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" - # eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd - # exit 1 fi } @@ -157,6 +150,15 @@ handle_task_before() { eval . $file_task_before "$@" $cmd } +handle_task_after() { + eval . $file_task_after "$@" $cmd + local end_time=$(date '+%Y-%m-%d %H:%M:%S') + local end_timestamp=$(date "+%s") + local diff_time=$(($end_timestamp - $begin_timestamp)) + [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" + eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd +} + ## 正常运行单个脚本,$1:传入参数 run_normal() { local file_param=$1 @@ -175,12 +177,7 @@ run_normal() { eval $timeoutCmd $which_program $file_param $cmd - eval . $file_task_after "$@" $cmd - local end_time=$(date '+%Y-%m-%d %H:%M:%S') - local end_timestamp=$(date "+%s") - local diff_time=$(expr $end_timestamp - $begin_timestamp) - [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" - eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd + handle_task_after "$@" } ## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行 @@ -233,12 +230,7 @@ run_concurrent() { [[ -f $single_log_path ]] && rm -f $single_log_path done - eval . $file_task_after "$@" $cmd - local end_time=$(date '+%Y-%m-%d %H:%M:%S') - local end_timestamp=$(date "+%s") - local diff_time=$(($end_timestamp - $begin_timestamp)) - [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" - eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd + handle_task_after "$@" } run_designated() { @@ -275,12 +267,7 @@ run_designated() { fi eval $timeoutCmd $which_program $file_param $cmd - eval . $file_task_after "$@" $cmd - local end_time=$(date '+%Y-%m-%d %H:%M:%S') - local end_timestamp=$(date "+%s") - local diff_time=$(($end_timestamp - $begin_timestamp)) - [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" - eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd + handle_task_after "$@" } ## 运行其他命令 @@ -299,12 +286,7 @@ run_else() { shift eval $timeoutCmd $which_program "$file_param" "$@" $cmd - eval . $file_task_after "$file_param" "$@" $cmd - local end_time=$(date '+%Y-%m-%d %H:%M:%S') - local end_timestamp=$(date "+%s") - local diff_time=$(($end_timestamp - $begin_timestamp)) - [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" - eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd + handle_task_after "$@" } ## 命令检测 diff --git a/src/version.ts b/src/version.ts index f1acb29c..23ab8a96 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,8 +1,6 @@ -export const version = '2.14.6'; -export const changeLogLink = 'https://t.me/jiao_long/333'; -export const changeLog = `2.14.6 版本说明 -1. 任务执行日志增加资源占用说明 -2. 配置文件config.sh增加资源配置参数CpuWarn/MemoryWarn/DiskWarn -3. 修复脚本管理和日志管理搜索 -4. 其他bug修复 +export const version = '2.14.7'; +export const changeLogLink = 'https://t.me/jiao_long/334'; +export const changeLog = `2.14.7 版本说明 +1. 修复task_before无法获取任务执行参数 +2. 修改资源判定逻辑 `;