完善ql repo命令

This commit is contained in:
whyour 2021-05-04 22:04:14 +08:00
parent 34775dd14d
commit bde7d6be03
7 changed files with 54 additions and 32 deletions

View File

@ -31,7 +31,11 @@ const run = async () => {
task.status !== CrontabStatus.disabled
) {
schedule.scheduleJob(task.schedule, function () {
exec(task.command);
let command = task.command as string;
if (!command.startsWith('task ')) {
command = `task ${command}`;
}
exec(command);
});
}
}

View File

@ -124,10 +124,11 @@ export default class CronService {
fs.writeFileSync(logFile, `开始执行...\n\n${new Date().toString()}\n`);
let cmdStr = res.command;
if (res.command.startsWith('js') && !res.command.endsWith('now')) {
cmdStr = `${res.command} now`;
} else if (/&& (.*) >>/.test(res.command)) {
cmdStr = res.command.match(/&& (.*) >>/)[1];
if (!res.command.startsWith('task')) {
cmdStr = `task ${cmdStr}`;
}
if (res.command.endsWith('.js')) {
cmdStr = `${cmdStr} now`;
}
const cmd = spawn(cmdStr, { shell: true });

View File

@ -4,9 +4,6 @@
dir_shell=/ql/shell
. $dir_shell/share.sh
## 导入配置文件
import_config
## 生成pt_pin清单
gen_pt_pin_array () {
local tmp1 tmp2 i pt_pin_temp

View File

@ -4,9 +4,6 @@
dir_shell=/ql/shell
. $dir_shell/share.sh
## 导入配置文件
import_config
days=$1
## 删除运行js脚本的旧日志

View File

@ -11,6 +11,7 @@ dir_db=$dir_root/db
dir_manual_log=$dir_root/manual_log
dir_list_tmp=$dir_log/.tmp
dir_code=$dir_log/code
dir_update_log=$dir_log/update
## 文件
file_config_sample=$dir_sample/config.sample.sh
@ -143,6 +144,7 @@ fix_config () {
make_dir $dir_scripts
make_dir $dir_list_tmp
make_dir $dir_raw
make_dir $dir_update_log
if [ ! -s $file_config_user ]; then
echo -e "复制一份 $file_config_sample$file_config_user,随后请按注释编辑你的配置文件:$file_config_user\n"

View File

@ -59,7 +59,6 @@ random_delay () {
## scripts目录下所有可运行脚本数组
gen_array_scripts () {
import_config
local dir_current=$(pwd)
local i="-1"
cd $dir_scripts
@ -79,13 +78,17 @@ usage () {
define_cmd
gen_array_scripts
echo -e "\ntask命令运行本程序自动添加进crontab的脚本需要输入脚本的绝对路径或去掉 “$dir_scripts/” 目录后的相对路径(定时任务中请写作相对路径),用法为:"
echo -e "1.$cmd_task <js_path> # 依次执行如果设置了随机延迟并且当时时间不在0-2、30-31、59分内将随机延迟一定秒数"
echo -e "2.$cmd_task <js_path> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中"
echo -e "3.$cmd_task <js_path> conc # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中"
echo -e "\n当前有以下脚本可以运行已省略路径 “$dir_scripts/” "
echo -e "1.$cmd_task <file_name> # 依次执行如果设置了随机延迟并且当时时间不在0-2、30-31、59分内将随机延迟一定秒数"
echo -e "2.$cmd_task <file_name> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中"
echo -e "3.$cmd_task <file_name> conc # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中"
if [[ ${#array_scripts[*]} -gt 0 ]]; then
echo -e "\n当前有以下脚本可以运行:"
for ((i=0; i<${#array_scripts[*]}; i++)); do
echo -e "$(($i + 1)). ${array_scripts_name[i]}${array_scripts[i]}"
done
else
echo -e "\n暂无脚本可以执行"
fi
}
## run nohup$1文件名不含路径带后缀
@ -98,14 +101,17 @@ run_nohup () {
run_normal () {
local p1=$1
cd $dir_scripts
import_config
define_program "$p1"
combine_all
if [[ $p1 == *.js ]]; then
if [[ $AutoHelpOther == true ]] && [[ $(ls $dir_code) ]]; then
local latest_log=$(ls -r $dir_code | head -1)
. $dir_code/$latest_log
fi
[[ $# -eq 1 ]] && random_delay
if [[ $# -eq 1 ]]; then
random_delay
fi
fi
log_time=$(date "+%Y-%m-%d-%H-%M-%S")
log_path="$dir_log/$p1/$log_time.log"
make_dir "$dir_log/$p1"
@ -117,7 +123,6 @@ run_normal () {
run_concurrent () {
local p1=$1
cd $dir_scripts
import_config
define_program "$p1"
make_dir $dir_log/$p1
log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")

View File

@ -306,7 +306,12 @@ gen_list_repo() {
fi
for file in ${files}; do
filename=$(basename $file)
local non_scripts=$(echo $filename | egrep jd | egrep -v "jd_")
if [[ -z $non_scripts ]]; then
cp -f $file $dir_scripts/${filename}
else
cp -f $file $dir_scripts/${author}_${filename}
fi
echo ${author}_${filename} >>$list_own_scripts
done
grep -E "$cmd_task $author" $list_crontab_user | perl -pe "s|.*ID=(.*) $cmd_task ($author_.*)\.*|\2|" | sort -u >$list_own_user
@ -315,7 +320,6 @@ gen_list_repo() {
## 重新编译qinglong
restart_qinglong() {
echo -e "--------------------------------------------------------------\n"
update_qinglong
if [[ $exit_status -eq 0 ]]; then
echo -e "重新编译青龙...\n"
@ -343,7 +347,6 @@ main() {
local p4=$4
log_time=$(date "+%Y-%m-%d-%H-%M-%S")
log_path="$dir_log/update/${log_time}_$p1.log"
make_dir "$dir_log/update"
case $p1 in
update)
update_qinglong | tee $log_path
@ -353,16 +356,29 @@ main() {
restart_qinglong | tee $log_path
;;
repo)
local name=$(echo "${p2##*/}" | awk -F "." '{print $1}')
log_path="$dir_log/update/${log_time}_$name.log"
if [[ -n $p2 ]]; then
update_repo "$p2" "$p3" "$p4" | tee $log_path
else
echo -e "命令输入错误...\n"
usage
;;
raw)
local name=$(echo "${p2##*/}" | awk -F "." '{print $1}')
log_path="$dir_log/update/${log_time}_$name.log"
if [[ -n $p2 ]]; then
update_raw "$p2" | tee $log_path
else
echo -e "命令输入错误...\n"
usage
;;
;;
rmlog)
source $dir_shell/rmlog.sh "$p2" | tee $log_path
. $dir_shell/rmlog.sh "$p2" | tee $log_path
;;
code)
source $dir_shell/code.sh
. $dir_shell/code.sh
;;
*)
echo -e "命令输入错误...\n"