mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 06:46:09 +08:00
修复ql命令日志
This commit is contained in:
parent
ce3543779e
commit
86e5f208fb
|
@ -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;
|
||||
|
|
|
@ -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 "$@"
|
||||
|
|
|
@ -108,10 +108,15 @@ const CronLogModal = ({
|
|||
<pre
|
||||
style={
|
||||
!isPhone
|
||||
? { whiteSpace: 'break-spaces', lineHeight: '17px' }
|
||||
? {
|
||||
whiteSpace: 'break-spaces',
|
||||
lineHeight: '17px',
|
||||
marginBottom: 0,
|
||||
}
|
||||
: {
|
||||
whiteSpace: 'break-spaces',
|
||||
lineHeight: '17px',
|
||||
marginBottom: 0,
|
||||
fontFamily: 'Source Code Pro',
|
||||
width: 375,
|
||||
zoom: 0.83,
|
||||
|
|
Loading…
Reference in New Issue
Block a user