From df1dc4fcbb681921d2423ed396f5297a766b7581 Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 3 Apr 2021 22:19:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=89=8B=E5=8A=A8=E6=89=A7?= =?UTF-8?q?=E8=A1=8Ccron=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 2 +- shell/api.sh | 6 +++--- shell/git_pull.sh | 8 +++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index 10b96ed6..2c67de42 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -74,7 +74,7 @@ export default class CronService { let logFile = `${config.manualLogPath}${res._id}.log`; fs.writeFileSync(logFile, `${new Date().toString()}\n\n`); - const cmd = spawn(res.command, { shell: true }); + const cmd = spawn(`${res.command} now`, { shell: true }); this.cronDb.update({ _id }, { $set: { status: CrontabStatus.running } }); diff --git a/shell/api.sh b/shell/api.sh index 7be48f48..556ed372 100755 --- a/shell/api.sh +++ b/shell/api.sh @@ -26,14 +26,14 @@ add_cron_api() { if [ $# -eq 1 ]; then local schedule=$(echo "$1" | awk -F ":" '{print $1}') local command=$(echo "$1" | awk -F ":" '{print $2}') - local name=$(echo "$1" | awk -F ": " '{print $3}') + local name=$(echo "$1" | awk -F ":" '{print $3}') else local schedule=$1 local command=$2 local name=$3 fi - local api=$(curl "http://localhost:5678/api/crons?t=$currentTimeStamp" \ + local api=$(curl "http://localhost:5600/api/crons?t=$currentTimeStamp" \ -H "Accept: application/json" \ -H "Authorization: Bearer $token" \ -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36" \ @@ -55,7 +55,7 @@ add_cron_api() { del_cron_api() { local id=$1 local currentTimeStamp=$(date +%s) - local api=$(curl "http://localhost:5678/api/crons/$id?t=$currentTimeStamp" \ + local api=$(curl "http://localhost:5600/api/crons/$id?t=$currentTimeStamp" \ -X 'DELETE' \ -H "Accept: application/json" \ -H "Authorization: Bearer $token" \ diff --git a/shell/git_pull.sh b/shell/git_pull.sh index 8de49dbf..014673aa 100755 --- a/shell/git_pull.sh +++ b/shell/git_pull.sh @@ -233,12 +233,10 @@ Add_Cron() { echo -e "开始尝试自动添加定时任务\n" JsAdd=$(cat $ListJsAdd) for Cron in $JsAdd; do - local id=$(echo "$1" | awk -F ":" '{print $1}') - local name=$(echo "$1" | awk -F ":" '{print $2}') - if [[ $name == jd_bean_sign ]]; then - echo "4 0,9 * * * $ShellJs $name" >>$ListCronCurrent + if [[ $Cron == jd_bean_sign ]]; then + echo "4 0,9 * * * $ShellJs $Cron" >>$ListCronCurrent else - param=$(cat $ListCronRemote | grep -E "\/$name\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1\:$ShellJs \2:\2|") + param=$(cat $ListCronRemote | grep -E "\/$Cron\." | perl -pe "s|(^.+)node */scripts/(j[drx]_\w+)\.js.+|\1\:$ShellJs \2:\2|") add_cron_api "$param" fi done