linux - 无法使用 JSch 从 Java 程序在远程服务器中执行 Linux shell 脚本
问题描述
我正在尝试使用 JSch 从 Java 程序在远程服务器中执行 Linux shell 脚本。当我登录到服务器并使用 putty 运行脚本时,我成功地执行了脚本,但是当我通过我的 Java 程序运行时,它给出了以下错误:
"<<script_name>>: Warning distribution home directory (HOME variable) is not defined or can't be read"
下面是我的Java程序:
JSch jsch = new JSch();
session = jsch.getSession(username, remoteHost);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
channelExec = (ChannelExec) session.openChannel("exec");
InputStream in = channelExec.getInputStream();
channelExec.setCommand("sh "+scriptFileName);
channelExec.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
result.add(line);
}
exitStatus = channelExec.getExitStatus();
请帮忙。我在我的项目中使用 Spring Boot。
解决方案
推荐阅读
- html - 悬停时不出现下拉菜单
- javascript - 正则表达式删除某些字符前后的引号
- javascript - firebase 云功能 - 部署错误找不到所需的模块
- python - 当每批中的观察值具有不同数量的缺失值时使用 Keras 掩蔽层
- ios - Swift - 在应用程序中显示来电者姓名
- omnet++ - 使用 MODE=release 构建 simuLTE 时出错
- node.js - 私有存储库的作用域 NPM 将斜杠“/”转换为“%2F”
- sql - 隐蔽左连接到简单连接
- azure - 如何在 Azure DevOps 中获取 keyvault 机密输出
- apache-flink - 尝试使用上传的 jar 开始新作业时出现 Flink REST API POST 错误