ch = (ChannelShell)ses.openChannel("shell"); ch.connect();
ChannelShell shellChannel = (ChannelShell) session.openChannel("shell"); shellChannel.setOutputStream(outputStream, true); InputStream in = new PipedInputStream(); PipedOutputStream pin = new PipedOutputStream((PipedInputStream) in); shellChannel.setInputStream(in); shellChannel.connect(); pin.write("ls \r").getBytes());
private void initShellConnection() throws JSchException, IOException { jsch = new JSch(); config = new Properties(); config.put("StrictHostKeyChecking", "no"); session = jsch.getSession("unknownid", "127.0.0.1", 22); session.setConfig(config); session.setPassword("unknownpw"); session.connect(CONNECTION_TIMEOUT); ChannelShell channel = (ChannelShell) session.openChannel("shell"); shellPrintStream = new PrintStream(channel.getOutputStream(), true); channel.setOutputStream(null); channel.setInputStream(null); channel.connect(CONNECTION_TIMEOUT); channel.setOutputStream(System.out); checkForRosCore(); }
private void setupSession(LocalCloudMachines machine, ImmutablePair<String, String> authPair) throws JSchException { Session session; session = jsch.getSession(authPair.getLeft(), machine.getIp(), 22); session.setConfig(config); session.setPassword(authPair.getRight()); session.connect(30000); sessions.put(machine, session); try { ChannelShell channel = (ChannelShell) sessions.get(machine).openChannel("shell"); shellPrintStreams.put(channel, new PrintStream(channel.getOutputStream(), true)); channel.setOutputStream(null); channel.setInputStream(null); channel.connect(CONNECTION_TIMEOUT); shellChannels.put(session, channel); channel.setOutputStream(System.out); } catch (IOException e) { e.printStackTrace(); } }
/** * Executes command using {@code shell} channel. * * @param ses SSH session. * @param cmd Command. * @throws JSchException In case of SSH error. * @throws IOException If IO error occurs. * @throws IgniteInterruptedCheckedException If thread was interrupted while waiting. */ private void shell(Session ses, String cmd) throws JSchException, IOException, IgniteInterruptedCheckedException { ChannelShell ch = null; try { ch = (ChannelShell)ses.openChannel("shell"); ch.connect(); try (PrintStream out = new PrintStream(ch.getOutputStream(), true)) { out.println(cmd); U.sleep(EXECUTE_WAIT_TIME); } } finally { if (ch != null && ch.isConnected()) ch.disconnect(); } }
final InputStream shellOut = channelShell.getInputStream(); channelShell.connect(connectTimeout);
/** * Executes command using {@code shell} channel. * * @param ses SSH session. * @param cmd Command. * @throws JSchException In case of SSH error. * @throws IOException If IO error occurs. * @throws GridInterruptedException If thread was interrupted while waiting. */ private void shell(Session ses, String cmd) throws JSchException, IOException, GridInterruptedException { ChannelShell ch = null; try { ch = (ChannelShell)ses.openChannel("shell"); ch.connect(); try (PrintStream out = new PrintStream(ch.getOutputStream(), true)) { out.println(cmd); U.sleep(1000); } } finally { if (ch != null && ch.isConnected()) ch.disconnect(); } }
final InputStream shellOut = channelShell.getInputStream(); channelShell.connect(connectTimeout);
channel.connect(5 * 1000);
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 String executeResponsiveShellJsch(){ ChannelShell channelShell = null; InputStream in = null; PrintStream ps = null; String response = null; LOGGER.info("executing command using shell - ", command); Session session = getSession(commandWritable, command); try { session.connect(); channelShell = (ChannelShell) session.openChannel("shell"); channelShell.setPty(true); in = channelShell.getInputStream(); channelShell.connect(); ps = new PrintStream(channelShell.getOutputStream(), true); ps.println(command.getCommandString()); ps.println("logout"); response = getStringFromStream(in); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } closeChannel(channelShell); closeSession(session); } return response; }
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 String executeResponsiveShellJsch(){ ChannelShell channelShell = null; InputStream in = null; PrintStream ps = null; String response = null; LOGGER.info("executing command using shell - ", command); Session session = getSession(commandWritable, command); try { session.connect(); channelShell = (ChannelShell) session.openChannel("shell"); channelShell.setPty(true); in = channelShell.getInputStream(); channelShell.connect(); ps = new PrintStream(channelShell.getOutputStream(), true); ps.println(command.getCommandString()); ps.println("logout"); response = getStringFromStream(in); } catch (Exception e) { LOGGER.error("Error ["+ e.getMessage() + "] while executing command [" +command.getCommandString()+"]"); } finally { if (ps != null) { ps.close(); } closeChannel(channelShell); closeSession(session); } return response; }
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); } }
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); } }
channel.setPtyType(term); channel.connect(); in = channel.getInputStream(); out = channel.getOutputStream();
channel.setPtyType(term); channel.connect(); in = channel.getInputStream(); out = channel.getOutputStream();
@Test public void testResizeHandler(TestContext context) throws Exception { Async async = context.async(); termHandler = term -> { term.resizehandler(v -> { context.assertEquals(20, term.width()); context.assertEquals(10, term.height()); async.complete(); }); }; startShell(); Session session = createSession("paulo", "secret", false); session.connect(); ChannelShell channel = (ChannelShell) session.openChannel("shell"); channel.connect(); OutputStream out = channel.getOutputStream(); channel.setPtySize(20, 10, 20 * 8, 10 * 8); out.flush(); channel.disconnect(); session.disconnect(); }