From f5b5c622a1cb7d11fc1f4f6ae5a3d9f693b04cbf Mon Sep 17 00:00:00 2001 From: hLinx <327159425@qq.com> Date: Wed, 29 May 2024 11:26:40 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=9B=B4=E6=96=B0shell=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=A8=A1=E6=9D=BF=EF=BC=8C=E8=A7=84=E9=81=BF=E4=BD=BF?= =?UTF-8?q?=E7=94=A8eval=E5=B8=A6=E6=9D=A5=E7=9A=84=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E9=A2=84=E6=9C=9F=E7=9A=84=E9=A3=8E=E9=99=A9=20#2992=20#=20Rev?= =?UTF-8?q?iewed,=20transaction=20id:=208896?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ace-editor/default-script.js | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/frontend/src/components/ace-editor/default-script.js b/src/frontend/src/components/ace-editor/default-script.js index 4471a0eb4f..6a19f12691 100644 --- a/src/frontend/src/components/ace-editor/default-script.js +++ b/src/frontend/src/components/ace-editor/default-script.js @@ -39,32 +39,36 @@ export default { shell.push( '#!/bin/bash', '', - 'anynowtime="date +\'%Y-%m-%d %H:%M:%S\'"', - 'NOW="echo [\\`$anynowtime\\`][PID:$$]"', '', - lang === 'zh-CN' ? '##### 可在脚本开始运行时调用,打印当时的时间戳及PID。' : '##### It\'s usually called when the script starts to run, prints the timestamp and PID.', + lang === 'zh-CN' ? '# 定义获取当前时间和PID的函数' : '# Define function to get current time and PID', + 'function job_get_now', + '{', + ' echo "[`date +\'%Y-%m-%d %H:%M:%S\'`][PID:$$]"', + '}', + '', + lang === 'zh-CN' ? '# 在脚本开始运行时调用,打印当前的时间戳及PID' : '# Call this function at the beginning of the script to print the current time and PID', 'function job_start', '{', - ' echo "`eval $NOW` job_start"', + ' echo "$(job_get_now) job_start"', '}', '', - lang === 'zh-CN' ? '##### 可在脚本执行成功的逻辑分支处调用,打印当时的时间戳及PID。 ' : '##### Use this func. to combine the execution results of multiple hosts and display by group.', + lang === 'zh-CN' ? '# 在脚本执行成功的逻辑分支处调用,打印当前的时间戳及PID' : '# Call this function when the script execution succeeds to print the current time and PID with a success message', 'function job_success', '{', - ' MSG="$*"', - ' echo "`eval $NOW` job_success:[$MSG]"', + ' local msg="$*"', + ' echo "$(job_get_now) job_success: [$msg]"', ' exit 0', '}', '', - // '#####可在脚本执行失败的逻辑分支处调用,打印当时的时间戳及PID。', - lang === 'zh-CN' ? '##### 可在脚本执行失败的逻辑分支处调用,打印当时的时间戳及PID。' : '##### Use this func. to combine the execution results of multiple hosts and display by group.', + lang === 'zh-CN' ? '# 在脚本执行失败的逻辑分支处调用,打印当前的时间戳及PID' : '# Call this function when the script execution fails to print the current time and PID with a failure message', 'function job_fail', '{', - ' MSG="$*"', - ' echo "`eval $NOW` job_fail:[$MSG]"', + ' local msg="$*"', + ' echo "$(job_get_now) job_fail: [$msg]"', ' exit 1', '}', '', + lang === 'zh-CN' ? '# 在当前脚本执行时,第一行输出当前时间和进程ID,详见上面函数:job_get_now' : '# Call the job_start function to print the current time and PID', 'job_start', '', lang === 'zh-CN' ? '###### 作业平台中执行脚本成功和失败的标准只取决于脚本最后一条执行语句的返回值' : '###### The script execution result is depends on the value of return/exit code, weather it success or failed.', @@ -72,6 +76,7 @@ export default { lang === 'zh-CN' ? '###### 可在此处开始编写您的脚本逻辑代码' : '###### Start to writing your script code below this line', '', '', + '', ); return shell.join('\n'); }()), @@ -125,6 +130,7 @@ export default { ' exit 1', '', '', + '', ); return batch.join('\n'); }()), @@ -165,6 +171,7 @@ export default { lang === 'zh-CN' ? '###### 可在此处开始编写您的脚本逻辑代码' : '###### You can start writing your script logic code here', '', '', + '', ); return perl.join('\n'); }()), @@ -207,6 +214,7 @@ export default { lang === 'zh-CN' ? '###### 可在此处开始编写您的脚本逻辑代码' : '###### Start to writing your script code below this line', '', '', + '', ); return python.join('\n'); }()), @@ -259,6 +267,7 @@ export default { lang === 'zh-CN' ? '###### 可在此处开始编写您的脚本逻辑代码' : '###### Start to writing your script code below this line', '', '', + '', ); return powershell.join('\n'); }()),