Commit 9444e50f authored by Quxl's avatar Quxl

x

parent 264137f3
...@@ -2,6 +2,8 @@ package com.egolm.sentinel.util; ...@@ -2,6 +2,8 @@ package com.egolm.sentinel.util;
import java.io.IOException; import java.io.IOException;
import com.egolm.common.StringUtil;
import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session; import ch.ethz.ssh2.Session;
...@@ -39,10 +41,20 @@ public class LinuxConnect { ...@@ -39,10 +41,20 @@ public class LinuxConnect {
connection.close(); connection.close();
} }
public Session execute(String cmd) throws IOException { public String execute(String cmd) throws IOException {
Session session = connection.openSession(); Session session = connection.openSession();;
try {
session.execCommand(cmd); session.execCommand(cmd);
return session; String message = StringUtil.read(session.getStdout());
if(StringUtil.isBlank(message)) {
message = StringUtil.read(session.getStderr());
}
return message;
} finally {
if(session != null) {
session.close();
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment