perf: ssh配置增加脚本类型设置,bash还是sh

v2-dev
xiaojunnuo 2025-09-09 18:14:14 +08:00
parent f41f7eb2ad
commit ae41c6038b
2 changed files with 26 additions and 2 deletions

View File

@ -64,6 +64,22 @@ export class SshAccess extends BaseAccess {
})
passphrase!: string;
@AccessInput({
title: "脚本类型",
helper: "bash 、sh 、fish",
component: {
name: "a-select",
vModel: "value",
options: [
{ value: "default", label: "默认" },
{ value: "sh", label: "sh" },
{ value: "bash", label: "bash" },
{ value: "fish", label: "fish(不支持set -e)" },
],
},
})
scriptType: string;
@AccessInput({
title: "伪终端",
helper: "如果登录报错all authentication methods failed可以尝试开启伪终端模式进行keyboard-interactive方式登录\n开启后对日志输出有一定的影响",

View File

@ -543,9 +543,17 @@ export class SshClient {
}
}
if (isLinux && options.stopOnError !== false) {
if (isLinux) {
if (options.connectConf.scriptType == "bash") {
script = "#!/usr/bin/env bash \n" + script;
} else if (options.connectConf.scriptType == "sh") {
script = "#!/bin/sh\n" + script;
}
if (options.connectConf.scriptType != "fish" && options.stopOnError !== false) {
script = "set -e\n" + script;
}
}
return await conn.exec(script as string, { throwOnStdErr });
},