diff --git a/back/services/cron.ts b/back/services/cron.ts index 4dcd522a..f6d76865 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -238,23 +238,35 @@ export default class CronService { public async log(_id: string) { const doc = await this.get(_id); - const commandStr = doc.command.split(' ')[1]; - const start = - commandStr.lastIndexOf('/') !== -1 ? commandStr.lastIndexOf('/') + 1 : 0; - const end = - commandStr.lastIndexOf('.') !== -1 - ? commandStr.lastIndexOf('.') - : commandStr.length; - const logPath = commandStr.substring(start, end); + const [, commandStr, url] = doc.command.split(' '); + let logPath = this.getKey(commandStr); + const isQlCommand = doc.command.startsWith('ql '); + const key = this.getKey(url) || logPath; + if (isQlCommand) { + logPath = 'update'; + } let logDir = `${config.logPath}${logPath}`; if (existsSync(logDir)) { - const files = await promises.readdir(logDir); + let files = await promises.readdir(logDir); + if (isQlCommand) { + files = files.filter((x) => x.includes(key)); + } return getFileContentByName(`${logDir}/${files[files.length - 1]}`); } else { return ''; } } + private getKey(command: string) { + const start = + command.lastIndexOf('/') !== -1 ? command.lastIndexOf('/') + 1 : 0; + const end = + command.lastIndexOf('.') !== -1 + ? command.lastIndexOf('.') + : command.length; + return command.substring(start, end); + } + private make_command(tab: Crontab) { const crontab_job_string = `ID=${tab._id} ${tab.command}`; return crontab_job_string; diff --git a/shell/update.sh b/shell/update.sh index 33cf3f0a..cade8f08 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -392,21 +392,25 @@ main() { local p4=$4 local p5=$5 local p6=$6 - log_time=$(date "+%Y-%m-%d-%H-%M-%S") - log_path="$dir_log/update/${log_time}_$p1.log" + local log_time=$(date "+%Y-%m-%d-%H-%M-%S") + local log_path="$dir_log/update/${log_time}_$p1.log" + local begin_time=$(date '+%Y-%m-%d %H:%M:%S') case $p1 in update) - update_qinglong "$2" | tee $log_path + echo -e "开始执行... $begin_time\n" >> $log_path + update_qinglong "$2" | tee -a $log_path ;; extra) + echo -e "开始执行... $begin_time\n" >> $log_path run_extra_shell | tee -a $log_path ;; repo) get_user_info local name=$(echo "${p2##*/}" | awk -F "." '{print $1}') log_path="$dir_log/update/${log_time}_$name.log" + echo -e "开始执行... $begin_time\n" >> $log_path if [[ -n $p2 ]]; then - update_repo "$p2" "$p3" "$p4" "$p5" "$p6" | tee $log_path + update_repo "$p2" "$p3" "$p4" "$p5" "$p6" | tee -a $log_path else echo -e "命令输入错误...\n" usage @@ -416,27 +420,34 @@ main() { get_user_info local name=$(echo "${p2##*/}" | awk -F "." '{print $1}') log_path="$dir_log/update/${log_time}_$name.log" + echo -e "开始执行... $begin_time\n" >> $log_path if [[ -n $p2 ]]; then - update_raw "$p2" | tee $log_path + update_raw "$p2" | tee -a $log_path else echo -e "命令输入错误...\n" usage fi ;; rmlog) - . $dir_shell/rmlog.sh "$p2" | tee $log_path + echo -e "开始执行... $begin_time\n" >> $log_path + . $dir_shell/rmlog.sh "$p2" | tee -a $log_path ;; bot) - . $dir_shell/bot.sh + echo -e "开始执行... $begin_time\n" >> $log_path + . $dir_shell/bot.sh | tee -a $log_path ;; reset) - . $dir_shell/reset.sh + echo -e "开始执行... $begin_time\n" >> $log_path + . $dir_shell/reset.sh | tee -a $log_path ;; *) echo -e "命令输入错误...\n" usage ;; esac + 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 秒" >> $log_path } main "$@" diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index 2cb32d7d..015a3e99 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -108,10 +108,15 @@ const CronLogModal = ({