0
我想通過SSH與JSch在遠程Linux服務器(不同端口上)上運行一些獨立的彈簧引導罐。我在我的命令中使用尾巴,因爲我需要tomcat服務器日誌。當我開始運行獨立罐子的服務時,一些罐子沒有運行。Jsch運行遠程jar與組合tail命令不能正常工作
下面是我使用獨立運行罐子的示例腳本:
nohup的Java的罐子foo.jar中--server.port = 10000> log.txt的2> ERRORS.TXT &尾-f日誌。 TXT
這裏是我的代碼:
StringBuilder sb = new StringBuilder();
Session session = null;
ChannelExec channel = null;
InputStreamReader isr = null;
BufferedReader br = null;
try {
String command1 = "nohup java -jar " + jarFileDir + "/" + jarFileName + " --server.port=" + port
+ " > " + jarFileDir + "/log.txt 2> " + jarFileDir + "/errors.txt & tail -f " + jarFileDir + "/log.txt";
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
session = jsch.getSession(username, ip, port);
session.setPassword(password);
session.setConfig(config);
session.connect();
channel = (ChannelExec)session.openChannel("exec");
channel.setPty(true);
isr = new InputStreamReader(channel.getInputStream());
br = new BufferedReader(isr);
channel.setCommand(command1);
channel.connect();
String msg;
while ((msg = br.readLine()) != null) {
//jar logs is being readed and processed here
}
} catch (Exception e) {
//handle exception
} finally {
//close all the connections
if (br != null) br.close();
if (isr != null) isr.close();
if (channel != null) channel.disconnect();
if (session != null) session.disconnect();
}
而且有關問題的日誌是在這裏:
尾:無法打開「log.txt的」閱讀:沒有這樣的文件或直接ORY 尾:沒有文件剩餘
上解決了這個問題。謝謝。 – Homeless