去掉有可能中断的tee

This commit is contained in:
hanhh 2021-08-02 18:57:48 +08:00
parent 59c9b17c40
commit 63f21b1698
2 changed files with 13 additions and 12 deletions

View File

@ -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
get_token

View File

@ -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