if (channel.getExitStatus() != 0) throw new Exception("exitStatus:" + channel.getExitStatus());
System.out.println("exit-status: " + channel.getExitStatus()); break;
if (in.available() > 0) continue; exitCode = channel.getExitStatus(); logger.info("[" + username + "@" + hostname + "] Command exit-status: " + exitCode);
if (in.available() > 0) continue; exitCode = channel.getExitStatus(); System.out.println("[" + username + "@" + hostname + "] Command exit-status: " + exitCode);
public int exitCode() throws IOException { return channel.getExitStatus(); }
private static void logJsch(Channel channel, InputStream in) { try { byte[] tmp = new byte[1024]; while (true) { /* while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) break; LOGGER.debug(new String(tmp, 0, i)); } */ if (channel.isClosed()) { LOGGER.debug("exit-status: " + channel.getExitStatus()); break; } } } catch (Exception ex) { LOGGER.error(ex); } }
private String read(InputStream is, Channel channel) throws IOException { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); final long endTime = System.currentTimeMillis() + TIMEOUT; while (System.currentTimeMillis() < endTime) { while (is.available() > 0) { int count = is.read(buffer, 0, DEFAULT_BUFFER_SIZE); if (count >= 0) { bos.write(buffer, 0, count); } else { break; } } if (channel.isClosed()) { if (log.isDebugEnabled()) { log.debug("SSH reading exit status=" + channel.getExitStatus()); } break; } try { Thread.sleep(POLL_TIMEOUT); } catch (InterruptedException e) { } } return bos.toString(); }
public void onOutput(Channel channel) { try { InputStream inputStream = channel.getInputStream(); byte[] tmp = new byte[1024]; while (true) { while (inputStream.available() > 0) { int i = inputStream.read(tmp, 0, 1024); if (i < 0) break; System.out.print(new String(tmp, 0, i)); } if (channel.isClosed()) { System.out.println("exit-status: " + channel.getExitStatus()); break; } try { Thread.sleep(1000); } catch (Exception ignored) { } } } catch (IOException e) { logger.error(e.getMessage(), e); } }
public static String getDaemonProcessId(Session session, String daemon) throws JSchException, IOException { String command = PID_COMMAND_PREFIX + daemon + PID_COMMAND_SUFFIX; session.connect(); Channel channel = session.openChannel("shell"); channel.connect(); OutputStream os = channel.getOutputStream(); InputStream is = channel.getInputStream(); PrintStream ps = new PrintStream(os, true); String pid = ""; try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { ps.println(command); for (String line = br.readLine(); line != null; line = br.readLine()) { if (line.contains(daemon) && !line.contains("awk ")) { pid = line.split("\\s+")[1]; } } } LOGGER.debug(" exit status - " + channel.getExitStatus() + ", daemon = " + daemon + ", PID = " + pid); if (channel != null && channel.isConnected()) { channel.disconnect(); } if (session != null && session.isConnected()) { session.disconnect(); } return pid; }
public static String getDaemonProcessId(Session session, String daemon) throws JSchException, IOException { String command = PID_COMMAND_PREFIX + daemon + PID_COMMAND_SUFFIX; session.connect(); Channel channel = session.openChannel("shell"); channel.connect(); OutputStream os = channel.getOutputStream(); InputStream is = channel.getInputStream(); PrintStream ps = new PrintStream(os, true); String pid = ""; try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { ps.println(command); for (String line = br.readLine(); line != null; line = br.readLine()) { if (line.contains(daemon) && !line.contains("awk ")) { pid = line.split("\\s+")[1]; } } } LOGGER.debug(" exit status - " + channel.getExitStatus() + ", daemon = " + daemon + ", PID = " + pid); if (channel != null && channel.isConnected()) { channel.disconnect(); } if (session != null && session.isConnected()) { session.disconnect(); } return pid; }
protected void execute(Channel channel, String pw) throws JSchException, IOException { channel.setInputStream(null); InputStream in=channel.getInputStream(); OutputStream out=channel.getOutputStream(); ((ChannelExec)channel).setErrStream(System.err); channel.connect(); if(!pw.isEmpty()){ out.write((pw+"\n").getBytes()); out.flush(); } byte[] tmp=new byte[1024]; while(true){ while(in.available()>0){ int i=in.read(tmp, 0, 1024); if(i<0)break; System.out.print(new String(tmp, 0, i)); } if(channel.isClosed()){ System.out.println("exit-status: "+channel.getExitStatus()); break; } try{Thread.sleep(1000);}catch(Exception ee){} } channel.disconnect(); } }
System.out.println("exit-status: "+channel.getExitStatus()); break;
System.out.println("exit-status: " + channel.getExitStatus());
journal.log(Level.INFO, ">> exit-status: "+channel.getExitStatus()); break;
System.out.println("exit-status: " + channel.getExitStatus()); break;
if(commandOutput.available()>0) continue; if (getExitStatus) { result += "exit-status: " + channel.getExitStatus(); if (withErr) { result += "\n With error:\n" + resultErr;
exitStatus = channel.getExitStatus(); if (log.isInfoEnabled()) { log.info("JSch channel exit-status: "
protected JschResponse getStringFromStream(Channel channel) throws IOException, JSchException { JschResponse jschResponse = new JschResponse(); StringBuilder response = new StringBuilder(); InputStream in = channel.getInputStream(); channel.connect(); jschResponse.setChannelId(channel.getId()); byte[] tmp = new byte[1024]; while (true) { while (in.available() > 0) { int i = in.read(tmp, 0, 1024); if (i < 0) break; response.append(new String(tmp, 0, i)); } if (channel.isClosed()) { if (in.available() > 0) continue; jschResponse.setChannelExitStatus(channel.getExitStatus()); break; } try { } catch (Exception ee) { LOGGER.error("Exception occured while reading stream from Channel #Id["+jschResponse.getChannelId()+"]", ee); } } jschResponse.setResponse(response.toString()); return jschResponse; }
result.setExitCode(channel.getExitStatus()); return result; } catch (JSchException | UnsupportedEncodingException e) {
result.setExitCode(channel.getExitStatus());