mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +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) {
|
public async log(_id: string) {
|
||||||
const doc = await this.get(_id);
|
const doc = await this.get(_id);
|
||||||
const commandStr = doc.command.split(' ')[1];
|
const [, commandStr, url] = doc.command.split(' ');
|
||||||
const start =
|
let logPath = this.getKey(commandStr);
|
||||||
commandStr.lastIndexOf('/') !== -1 ? commandStr.lastIndexOf('/') + 1 : 0;
|
const isQlCommand = doc.command.startsWith('ql ');
|
||||||
const end =
|
const key = this.getKey(url) || logPath;
|
||||||
commandStr.lastIndexOf('.') !== -1
|
if (isQlCommand) {
|
||||||
? commandStr.lastIndexOf('.')
|
logPath = 'update';
|
||||||
: commandStr.length;
|
}
|
||||||
const logPath = commandStr.substring(start, end);
|
|
||||||
let logDir = `${config.logPath}${logPath}`;
|
let logDir = `${config.logPath}${logPath}`;
|
||||||
if (existsSync(logDir)) {
|
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]}`);
|
return getFileContentByName(`${logDir}/${files[files.length - 1]}`);
|
||||||
} else {
|
} else {
|
||||||
return '';
|
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) {
|
private make_command(tab: Crontab) {
|
||||||
const crontab_job_string = `ID=${tab._id} ${tab.command}`;
|
const crontab_job_string = `ID=${tab._id} ${tab.command}`;
|
||||||
return crontab_job_string;
|
return crontab_job_string;
|
||||||
|
|
|
@ -392,21 +392,25 @@ main() {
|
||||||
local p4=$4
|
local p4=$4
|
||||||
local p5=$5
|
local p5=$5
|
||||||
local p6=$6
|
local p6=$6
|
||||||
log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||||
log_path="$dir_log/update/${log_time}_$p1.log"
|
local log_path="$dir_log/update/${log_time}_$p1.log"
|
||||||
|
local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
|
||||||
case $p1 in
|
case $p1 in
|
||||||
update)
|
update)
|
||||||
update_qinglong "$2" | tee $log_path
|
echo -e "开始执行... $begin_time\n" >> $log_path
|
||||||
|
update_qinglong "$2" | tee -a $log_path
|
||||||
;;
|
;;
|
||||||
extra)
|
extra)
|
||||||
|
echo -e "开始执行... $begin_time\n" >> $log_path
|
||||||
run_extra_shell | tee -a $log_path
|
run_extra_shell | tee -a $log_path
|
||||||
;;
|
;;
|
||||||
repo)
|
repo)
|
||||||
get_user_info
|
get_user_info
|
||||||
local name=$(echo "${p2##*/}" | awk -F "." '{print $1}')
|
local name=$(echo "${p2##*/}" | awk -F "." '{print $1}')
|
||||||
log_path="$dir_log/update/${log_time}_$name.log"
|
log_path="$dir_log/update/${log_time}_$name.log"
|
||||||
|
echo -e "开始执行... $begin_time\n" >> $log_path
|
||||||
if [[ -n $p2 ]]; then
|
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
|
else
|
||||||
echo -e "命令输入错误...\n"
|
echo -e "命令输入错误...\n"
|
||||||
usage
|
usage
|
||||||
|
@ -416,27 +420,34 @@ main() {
|
||||||
get_user_info
|
get_user_info
|
||||||
local name=$(echo "${p2##*/}" | awk -F "." '{print $1}')
|
local name=$(echo "${p2##*/}" | awk -F "." '{print $1}')
|
||||||
log_path="$dir_log/update/${log_time}_$name.log"
|
log_path="$dir_log/update/${log_time}_$name.log"
|
||||||
|
echo -e "开始执行... $begin_time\n" >> $log_path
|
||||||
if [[ -n $p2 ]]; then
|
if [[ -n $p2 ]]; then
|
||||||
update_raw "$p2" | tee $log_path
|
update_raw "$p2" | tee -a $log_path
|
||||||
else
|
else
|
||||||
echo -e "命令输入错误...\n"
|
echo -e "命令输入错误...\n"
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
rmlog)
|
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)
|
bot)
|
||||||
. $dir_shell/bot.sh
|
echo -e "开始执行... $begin_time\n" >> $log_path
|
||||||
|
. $dir_shell/bot.sh | tee -a $log_path
|
||||||
;;
|
;;
|
||||||
reset)
|
reset)
|
||||||
. $dir_shell/reset.sh
|
echo -e "开始执行... $begin_time\n" >> $log_path
|
||||||
|
. $dir_shell/reset.sh | tee -a $log_path
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "命令输入错误...\n"
|
echo -e "命令输入错误...\n"
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
esac
|
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 "$@"
|
main "$@"
|
||||||
|
|
|
@ -108,10 +108,15 @@ const CronLogModal = ({
|
||||||
<pre
|
<pre
|
||||||
style={
|
style={
|
||||||
!isPhone
|
!isPhone
|
||||||
? { whiteSpace: 'break-spaces', lineHeight: '17px' }
|
? {
|
||||||
|
whiteSpace: 'break-spaces',
|
||||||
|
lineHeight: '17px',
|
||||||
|
marginBottom: 0,
|
||||||
|
}
|
||||||
: {
|
: {
|
||||||
whiteSpace: 'break-spaces',
|
whiteSpace: 'break-spaces',
|
||||||
lineHeight: '17px',
|
lineHeight: '17px',
|
||||||
|
marginBottom: 0,
|
||||||
fontFamily: 'Source Code Pro',
|
fontFamily: 'Source Code Pro',
|
||||||
width: 375,
|
width: 375,
|
||||||
zoom: 0.83,
|
zoom: 0.83,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user