✨ windows 使用脚本执行命令.
This commit is contained in:
@@ -19,25 +19,34 @@ public class PathUtils {
|
|||||||
/**
|
/**
|
||||||
* 获取用户根目录
|
* 获取用户根目录
|
||||||
*
|
*
|
||||||
|
* @param isWindows isWindows
|
||||||
* @param username 用户名
|
* @param username 用户名
|
||||||
* @return 用户目录
|
* @return 用户目录
|
||||||
*/
|
*/
|
||||||
public static String getHomePath(String username) {
|
public static String getHomePath(boolean isWindows, String username) {
|
||||||
|
if (isWindows) {
|
||||||
|
// windows
|
||||||
|
return "C:/Users/" + username;
|
||||||
|
} else {
|
||||||
|
// linux
|
||||||
if (Const.ROOT.equals(username)) {
|
if (Const.ROOT.equals(username)) {
|
||||||
return "/" + Const.ROOT;
|
return "/" + Const.ROOT;
|
||||||
} else {
|
} else {
|
||||||
return "/home/" + username;
|
return "/home/" + username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取应用路径
|
* 获取应用路径
|
||||||
*
|
*
|
||||||
|
* @param isWindows isWindows
|
||||||
* @param username username
|
* @param username username
|
||||||
* @return path
|
* @return path
|
||||||
*/
|
*/
|
||||||
public static String getAppPath(String username) {
|
public static String getAppPath(boolean isWindows, String username) {
|
||||||
return getHomePath(username)
|
return getHomePath(isWindows, username)
|
||||||
+ "/" + AppConst.ORION
|
+ "/" + AppConst.ORION
|
||||||
+ "/" + AppConst.ORION_OPS_PRO;
|
+ "/" + AppConst.ORION_OPS_PRO;
|
||||||
}
|
}
|
||||||
@@ -45,12 +54,13 @@ public class PathUtils {
|
|||||||
/**
|
/**
|
||||||
* 构建应用路径
|
* 构建应用路径
|
||||||
*
|
*
|
||||||
|
* @param isWindows isWindows,
|
||||||
* @param username username
|
* @param username username
|
||||||
* @param paths paths
|
* @param paths paths
|
||||||
* @return path
|
* @return path
|
||||||
*/
|
*/
|
||||||
public static String buildAppPath(String username, Object... paths) {
|
public static String buildAppPath(boolean isWindows, String username, Object... paths) {
|
||||||
StringBuilder path = new StringBuilder(getAppPath(username));
|
StringBuilder path = new StringBuilder(getAppPath(isWindows, username));
|
||||||
for (Object o : paths) {
|
for (Object o : paths) {
|
||||||
path.append("/").append(Objects1.toString(o));
|
path.append("/").append(Objects1.toString(o));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ spring:
|
|||||||
tablePrefix: QRTZ_
|
tablePrefix: QRTZ_
|
||||||
misfireThreshold: 60000
|
misfireThreshold: 60000
|
||||||
clusterCheckinInterval: 5000
|
clusterCheckinInterval: 5000
|
||||||
# 打开群集功能
|
isClustered: true
|
||||||
isClustered: false
|
|
||||||
#连接池
|
#连接池
|
||||||
threadPool:
|
threadPool:
|
||||||
class: org.quartz.simpl.SimpleThreadPool
|
class: org.quartz.simpl.SimpleThreadPool
|
||||||
|
|||||||
@@ -146,11 +146,18 @@ public class ExecCommandHandler implements IExecCommandHandler {
|
|||||||
// 打开 sftp
|
// 打开 sftp
|
||||||
sftpExecutor = sessionStore.getSftpExecutor(execHostCommand.getFileNameCharset());
|
sftpExecutor = sessionStore.getSftpExecutor(execHostCommand.getFileNameCharset());
|
||||||
sftpExecutor.connect();
|
sftpExecutor.connect();
|
||||||
// 上传文件
|
// 必须要以 / 开头
|
||||||
|
String scriptPath = execHostCommand.getScriptPath();
|
||||||
|
if (!scriptPath.startsWith("/")) {
|
||||||
|
scriptPath = "/" + scriptPath;
|
||||||
|
}
|
||||||
|
// 创建文件
|
||||||
|
sftpExecutor.touch(scriptPath);
|
||||||
|
// 写入命令
|
||||||
byte[] command = Strings.replaceCRLF(execHostCommand.getCommand()).getBytes(execHostCommand.getFileContentCharset());
|
byte[] command = Strings.replaceCRLF(execHostCommand.getCommand()).getBytes(execHostCommand.getFileContentCharset());
|
||||||
sftpExecutor.write(execHostCommand.getScriptPath(), command);
|
sftpExecutor.write(scriptPath, command);
|
||||||
// 修改权限
|
// 修改权限
|
||||||
sftpExecutor.changeMode(execHostCommand.getScriptPath(), 777);
|
sftpExecutor.changeMode(scriptPath, 777);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw Exceptions.sftp(e);
|
throw Exceptions.sftp(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class TransferMessageDispatcher extends AbstractWebSocketHandler {
|
|||||||
String id = session.getId();
|
String id = session.getId();
|
||||||
log.info("TransferMessageHandler-afterConnectionClosed id: {}, code: {}, reason: {}", id, status.getCode(), status.getReason());
|
log.info("TransferMessageHandler-afterConnectionClosed id: {}, code: {}, reason: {}", id, status.getCode(), status.getReason());
|
||||||
// 关闭会话
|
// 关闭会话
|
||||||
Streams.close(handlers.get(id));
|
Streams.close(handlers.remove(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -349,11 +349,12 @@ public class ExecCommandServiceImpl implements ExecCommandService {
|
|||||||
* @return scriptPath
|
* @return scriptPath
|
||||||
*/
|
*/
|
||||||
private String buildScriptPath(String username, String osType, Long logId, Long hostId) {
|
private String buildScriptPath(String username, String osType, Long logId, Long hostId) {
|
||||||
|
HostSshOsTypeEnum os = HostSshOsTypeEnum.of(osType);
|
||||||
String name = PathConst.EXEC
|
String name = PathConst.EXEC
|
||||||
+ "_" + logId
|
+ "_" + logId
|
||||||
+ "_" + hostId
|
+ "_" + hostId
|
||||||
+ HostSshOsTypeEnum.of(osType).getScriptSuffix();
|
+ os.getScriptSuffix();
|
||||||
return PathUtils.buildAppPath(username, PathConst.SCRIPT, name);
|
return PathUtils.buildAppPath(HostSshOsTypeEnum.WINDOWS.equals(os), username, PathConst.SCRIPT, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-drawer v-model:visible="visible"
|
<a-drawer v-model:visible="visible"
|
||||||
:width="420"
|
:width="460"
|
||||||
:esc-to-close="false"
|
:esc-to-close="false"
|
||||||
:mask-closable="false"
|
:mask-closable="false"
|
||||||
:unmount-on-close="true"
|
:unmount-on-close="true"
|
||||||
|
|||||||
Reference in New Issue
Block a user