public ChannelReaderResponse executeResponsiveShellJsch(Session session, Command command){ ChannelReaderResponse channelReaderResponse = new ChannelReaderResponse(); ChannelShell channelShell = null; BufferedReader br = null; PrintStream ps = null; try { session.connect(); channelShell = (ChannelShell) session.openChannel("shell"); channelShell.setPty(true); br = new BufferedReader(new InputStreamReader( channelShell.getInputStream())); channelShell.connect(); ps = new PrintStream(channelShell.getOutputStream(), true); ps.println(command.getCommandString()); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } } channelReaderResponse.setChannel(channelShell); channelReaderResponse.setReader(br); channelReaderResponse.setExitCode(channelShell.getExitStatus()); return channelReaderResponse; }
public void executeShellJsch() { ChannelShell channelShell = null; PrintStream ps = null; Session session = getSession(commandWritable, command); String errorDebug = "DEBUG EMPTY"; try { session.connect(); channelShell = (ChannelShell) session.openChannel("shell"); channelShell.setPty(true); InputStream is = channelShell.getInputStream(); channelShell.connect(); ps = new PrintStream(channelShell.getOutputStream(), true); ps.println(command.getCommandString()); ps.println("logout"); errorDebug = logJsch(channelShell, is); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } LOGGER.info("Shell JSch - Executed command [" + command.getCommandString() +"], exit code [" + channelShell.getExitStatus()+"]"); if(channelShell.getExitStatus()!=0){ LOGGER.error("Detailed Debug log for Errored command [" + command.getCommandString() +"]\n ----- \n"+errorDebug +"\n-----"); } closeChannel(channelShell); closeSession(session); } }
public ChannelReaderResponse executeResponsiveShellJsch(Session session, Command command){ ChannelReaderResponse channelReaderResponse = new ChannelReaderResponse(); ChannelShell channelShell = null; BufferedReader br = null; PrintStream ps = null; try { session.connect(); channelShell = (ChannelShell) session.openChannel("shell"); channelShell.setPty(true); br = new BufferedReader(new InputStreamReader( channelShell.getInputStream())); channelShell.connect(); ps = new PrintStream(channelShell.getOutputStream(), true); ps.println(command.getCommandString()); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } } channelReaderResponse.setChannel(channelShell); channelReaderResponse.setReader(br); channelReaderResponse.setExitCode(channelShell.getExitStatus()); return channelReaderResponse; }
public void executeShellJsch(CommandWritable commandWritable, Command command) { ChannelShell channelShell = null; PrintStream ps = null; Session session = getSession(commandWritable, command); String errorDebug = "DEBUG EMPTY"; try { session.connect(); channelShell = (ChannelShell) session.openChannel("shell"); channelShell.setPty(true); InputStream is = channelShell.getInputStream(); channelShell.connect(); ps = new PrintStream(channelShell.getOutputStream(), true); ps.println(command.getCommandString()); ps.println("logout"); errorDebug = logJsch(channelShell, is); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } LOGGER.info("Shell JSch - Executed command [" + command.getCommandString() +"], exit code [" + channelShell.getExitStatus()+"]"); if(channelShell.getExitStatus()!=0){ LOGGER.error("Detailed Debug log for Errored command [" + command.getCommandString() +"]\n ----- \n"+errorDebug +"\n-----"); } closeChannel(channelShell); closeSession(session); } }
public void executeShellJsch() { ChannelShell channelShell = null; PrintStream ps = null; Session session = getSession(commandWritable, command); String errorDebug = "DEBUG EMPTY"; try { session.connect(); channelShell = (ChannelShell) session.openChannel("shell"); channelShell.setPty(true); InputStream is = channelShell.getInputStream(); channelShell.connect(); ps = new PrintStream(channelShell.getOutputStream(), true); ps.println(command.getCommandString()); ps.println("logout"); errorDebug = logJsch(channelShell, is); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } LOGGER.info("Shell JSch - Executed command [" + command.getCommandString() +"], exit code [" + channelShell.getExitStatus()+"]"); if(channelShell.getExitStatus()!=0){ LOGGER.error("Detailed Debug log for Errored command [" + command.getCommandString() +"]\n ----- \n"+errorDebug +"\n-----"); } closeChannel(channelShell); closeSession(session); } }
public void executeShellJsch(CommandWritable commandWritable, Command command) { ChannelShell channelShell = null; PrintStream ps = null; Session session = getSession(commandWritable, command); String errorDebug = "DEBUG EMPTY"; try { session.connect(); channelShell = (ChannelShell) session.openChannel("shell"); channelShell.setPty(true); InputStream is = channelShell.getInputStream(); channelShell.connect(); ps = new PrintStream(channelShell.getOutputStream(), true); ps.println(command.getCommandString()); ps.println("logout"); errorDebug = logJsch(channelShell, is); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } LOGGER.info("Shell JSch - Executed command [" + command.getCommandString() +"], exit code [" + channelShell.getExitStatus()+"]"); if(channelShell.getExitStatus()!=0){ LOGGER.error("Detailed Debug log for Errored command [" + command.getCommandString() +"]\n ----- \n"+errorDebug +"\n-----"); } closeChannel(channelShell); closeSession(session); } }
if (logger.isInfoEnabled()) { logger.info("[GSSH]-shell exit status is " + channel.getExitStatus());
return new TerminalResponse(shell.getExitStatus(), buffer.toString()); } catch (final SshTimeoutException e) { throw e;
@Test public void testExitCode() throws Exception { server(conn -> { conn.setStdinHandler(bytes -> { conn.close(25); }); }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }
@Test public void testExitCode() throws Exception { server(new Consumer<TtyConnection>() { @Override public void accept(final TtyConnection conn) { conn.setStdinHandler(new Consumer<int[]>() { @Override public void accept(int[] bytes) { conn.close(25); } }); } }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }
@Test public void testExitCode() throws Exception { server(conn -> { conn.setStdinHandler(bytes -> { conn.close(25); }); }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }