修复task_before, task_after

This commit is contained in:
hanhh 2021-07-17 01:33:10 +08:00
parent 9d8c592e69
commit 20ddb5a3cf
2 changed files with 23 additions and 23 deletions

View File

@ -170,9 +170,9 @@ update_cron() {
code=$(echo $api | jq -r .code) code=$(echo $api | jq -r .code)
message=$(echo $api | jq -r .message) message=$(echo $api | jq -r .message)
if [[ $code == 200 ]]; then if [[ $code == 200 ]]; then
echo -e "## 更新任务状态成功" | tee --output-error=warn -a $log_path echo -e "## 更新任务状态成功" | tee -p -a $log_path
else else
echo -e "## 更新任务状态失败(${message})" | tee --output-error=warn -a $log_path echo -e "## 更新任务状态失败(${message})" | tee -p -a $log_path
fi fi
} }

View File

@ -91,25 +91,25 @@ 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 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') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee --output-error=warn -a $log_path echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path"
if [[ ! $(. $file_task_before) ]]; then if [[ ! $(. $file_task_before 1>/dev/null) ]]; then
. $file_task_before . $file_task_before
else else
echo -e "## task_before执行失败自行检查\n" | tee --output-error=warn -a $log_path echo -e "## task_before执行失败自行检查\n" | tee -p -a $log_path
fi fi
timeout $command_timeout_time $which_program $p1 2>&1 | tee --output-error=warn -a $log_path timeout $command_timeout_time $which_program $p1 2>&1 | tee -p -a $log_path
if [[ ! $(. $file_task_after) ]]; then if [[ ! $(. $file_task_after 1>/dev/null) ]]; then
. $file_task_after . $file_task_after
else else
echo -e "## task_after执行失败自行检查\n" | tee --output-error=warn -a $log_path echo -e "## task_after执行失败自行检查\n" | tee -p -a $log_path
fi fi
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S') local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
echo -e "\n## 执行结束... $end_time 耗时 $diff_time" | tee --output-error=warn -a $log_path echo -e "\n## 执行结束... $end_time 耗时 $diff_time" | tee -p -a $log_path
} }
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行 ## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
@ -133,14 +133,14 @@ 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 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') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee --output-error=warn -a $log_path echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path"
if [[ ! $(. $file_task_before) ]]; then if [[ ! $(. $file_task_before 1>/dev/null) ]]; then
. $file_task_before . $file_task_before
else else
echo -e "## task_before执行失败自行检查\n" | tee --output-error=warn -a $log_path echo -e "## task_before执行失败自行检查\n" | tee -p -a $log_path
fi fi
echo -e "\n各账号间已经在后台开始并发执行前台不输入日志日志直接写入文件中。\n" | tee --output-error=warn -a $log_path echo -e "\n各账号间已经在后台开始并发执行前台不输入日志日志直接写入文件中。\n" | tee -p -a $log_path
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
@ -149,15 +149,15 @@ run_concurrent() {
timeout $command_timeout_time $which_program $p1 &>$single_log_path & timeout $command_timeout_time $which_program $p1 &>$single_log_path &
done done
if [[ ! $(. $file_task_after) ]]; then if [[ ! $(. $file_task_after 1>/dev/null) ]]; then
. $file_task_after . $file_task_after
else else
echo -e "## task_after执行失败自行检查\n" | tee --output-error=warn -a $log_path echo -e "## task_after执行失败自行检查\n" | tee -p -a $log_path
fi fi
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S') local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
echo -e "\n## 执行结束... $end_time 耗时 $diff_time" | tee --output-error=warn -a $log_path echo -e "\n## 执行结束... $end_time 耗时 $diff_time" | tee -p -a $log_path
} }
## 运行其他命令 ## 运行其他命令
@ -170,25 +170,25 @@ 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 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') local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "## 开始执行... $begin_time\n" | tee --output-error=warn -a $log_path echo -e "## 开始执行... $begin_time\n" | tee -p -a $log_path
[[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path" [[ $id ]] && update_cron "\"$id\"" "0" "$$" "$log_path"
if [[ ! $(. $file_task_before) ]]; then if [[ ! $(. $file_task_before 1>/dev/null) ]]; then
. $file_task_before . $file_task_before
else else
echo -e "## task_before执行失败自行检查\n" | tee --output-error=warn -a $log_path echo -e "## task_before执行失败自行检查\n" | tee -p -a $log_path
fi fi
timeout $command_timeout_time "$@" 2>&1 | tee --output-error=warn -a $log_path timeout $command_timeout_time "$@" 2>&1 | tee -p -a $log_path
if [[ ! $(. $file_task_after) ]]; then if [[ ! $(. $file_task_after 1>/dev/null) ]]; then
. $file_task_after . $file_task_after
else else
echo -e "## task_after执行失败自行检查\n" | tee --output-error=warn -a $log_path echo -e "## task_after执行失败自行检查\n" | tee -p -a $log_path
fi fi
[[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path" [[ $id ]] && update_cron "\"$id\"" "1" "" "$log_path"
local end_time=$(date '+%Y-%m-%d %H:%M:%S') local end_time=$(date '+%Y-%m-%d %H:%M:%S')
local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time"))) local diff_time=$(($(date +%s -d "$end_time") - $(date +%s -d "$begin_time")))
echo -e "\n## 执行结束... $end_time 耗时 $diff_time" | tee --output-error=warn -a $log_path echo -e "\n## 执行结束... $end_time 耗时 $diff_time" | tee -p -a $log_path
} }
## 命令检测 ## 命令检测