diff --git a/back/schedule.ts b/back/schedule.ts index 6cb4f6e6..f0e662eb 100644 --- a/back/schedule.ts +++ b/back/schedule.ts @@ -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); }); } } diff --git a/back/services/cron.ts b/back/services/cron.ts index 64020020..97a9b72f 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -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 }); diff --git a/shell/code.sh b/shell/code.sh index fadef0f9..9f2e2749 100755 --- a/shell/code.sh +++ b/shell/code.sh @@ -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 diff --git a/shell/rmlog.sh b/shell/rmlog.sh index bc47a089..2eaaee35 100755 --- a/shell/rmlog.sh +++ b/shell/rmlog.sh @@ -4,9 +4,6 @@ dir_shell=/ql/shell . $dir_shell/share.sh -## 导入配置文件 -import_config - days=$1 ## 删除运行js脚本的旧日志 diff --git a/shell/share.sh b/shell/share.sh index 59f3b6cc..55df86f2 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -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" diff --git a/shell/task.sh b/shell/task.sh index 27ebcb4d..4cb9dff1 100755 --- a/shell/task.sh +++ b/shell/task.sh @@ -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 # 依次执行,如果设置了随机延迟并且当时时间不在0-2、30-31、59分内,将随机延迟一定秒数" - echo -e "2.$cmd_task now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中" - echo -e "3.$cmd_task conc # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中" - echo -e "\n当前有以下脚本可以运行(已省略路径 “$dir_scripts/” ):" - for ((i=0; i<${#array_scripts[*]}; i++)); do - echo -e "$(($i + 1)). ${array_scripts_name[i]}:${array_scripts[i]}" - done + echo -e "1.$cmd_task # 依次执行,如果设置了随机延迟并且当时时间不在0-2、30-31、59分内,将随机延迟一定秒数" + echo -e "2.$cmd_task now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中" + echo -e "3.$cmd_task 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 [[ $AutoHelpOther == true ]] && [[ $(ls $dir_code) ]]; then - local latest_log=$(ls -r $dir_code | head -1) - . $dir_code/$latest_log + 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 + if [[ $# -eq 1 ]]; then + random_delay + fi fi - [[ $# -eq 1 ]] && random_delay 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") diff --git a/shell/update.sh b/shell/update.sh index 214c0a27..1f8be6ee 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -306,7 +306,12 @@ gen_list_repo() { fi for file in ${files}; do filename=$(basename $file) - cp -f $file $dir_scripts/${author}_${filename} + 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) - update_repo "$p2" "$p3" "$p4" | tee $log_path + 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) - update_raw "$p2" | tee $log_path + 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"