mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修复task_before, task_after
This commit is contained in:
parent
9d8c592e69
commit
20ddb5a3cf
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
## 命令检测
|
## 命令检测
|
||||||
|
|
Loading…
Reference in New Issue
Block a user