use of com.orion.remote.channel.ssh.CommandExecutor in project orion-kit by lijiahangmax.
the class CommandExecutorTests method test1.
@Test
public void test1() throws IOException {
SessionHolder.addIdentity("C:\\Users\\ljh15\\Desktop\\env", "admin123");
SessionStore store = SessionHolder.getSession("192.168.146.230", "root").connect();
CommandExecutor executor = store.getCommandExecutor("echo $JAVA_HOME");
executor.inherit().connect();
System.out.println(SessionStore.getCommandOutputResultString(executor));
executor.close();
store.close();
}
use of com.orion.remote.channel.ssh.CommandExecutor in project orion-kit by lijiahangmax.
the class CommandExecutorTests method test3.
@Test
public void test3() throws IOException {
SessionStore store = SessionHolder.getSession("192.168.146.230", "root").setPassword("admin123").connect();
CommandExecutor executor = store.getCommandExecutor("ec111ho 1");
executor.inherit().connect();
System.out.println(SessionStore.getCommandOutputResultString(executor));
executor.close();
store.close();
}
use of com.orion.remote.channel.ssh.CommandExecutor in project orion-kit by lijiahangmax.
the class CommandExecutorTests method test2.
@Test
public void test2() throws IOException {
SessionStore store = SessionHolder.getSession("192.168.146.230", "root").setPassword("admin123").connect();
CommandExecutor executor = store.getCommandExecutor("/bin/bash -c 'echo $JAVA_HOME'");
executor.inherit().connect();
System.out.println(SessionStore.getCommandOutputResultString(executor));
executor.close();
store.close();
}
use of com.orion.remote.channel.ssh.CommandExecutor in project orion-ops by lijiahangmax.
the class MachineInfoServiceImpl method runRemoteCommand.
/**
* 执行远程机器命令
*/
private String runRemoteCommand(Long id, String command) {
SessionStore session = null;
CommandExecutor executor = null;
try {
session = this.openSessionStore(id);
executor = session.getCommandExecutor(Strings.replaceCRLF(command));
executor.connect();
String res = SessionStore.getCommandOutputResultString(executor);
log.info("执行机器命令-成功 {} {} {}", id, command, res);
return res;
} catch (Exception e) {
log.error("执行机器命令-失败 {} {} {}", id, command, e);
if (e instanceof IOException) {
throw Exceptions.ioRuntime(e);
} else if (e instanceof ConnectionRuntimeException) {
throw (ConnectionRuntimeException) e;
} else if (e instanceof AuthenticationException) {
throw (AuthenticationException) e;
}
return null;
} finally {
Streams.close(executor);
Streams.close(session);
}
}
use of com.orion.remote.channel.ssh.CommandExecutor in project orion-kit by lijiahangmax.
the class CommandExecutorTests method ls.
private static void ls() {
SessionHolder.setLogger(SessionLogger.ERROR);
CommandExecutor e = SessionHolder.getSession("192.168.146.230", "root").setPassword("admin123").setTimeout(20000).connect(20000).getCommandExecutor("ls -la /a/b/c");
e.callback(exe -> {
System.out.println("end....");
System.out.println(e.getExitCode());
e.close();
});
e.streamHandler(ReaderLineConsumer.getDefaultPrint());
e.errorStreamHandler(ReaderLineConsumer.getDefaultPrint());
e.connect().exec();
}
Aggregations