Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. JSch jsch = new JSch();
  2.  
  3. String user = "otc";
  4. String host = "p6-m1mp";
  5. String password = "mypassword"
  6. int port = 22;
  7.  
  8. Session session = jsch.getSession(user, host, port);
  9. System.out.println("session created.");
  10. session.setConfig("StrictHostKeyChecking", "no");
  11. session.setPassword(password);
  12. session.connect();
  13.  
  14. ChannelExec channel=(ChannelExec) session.openChannel("exec");
  15. BufferedReader in=new BufferedReader(new InputStreamReader(channel.getInputStream()));
  16. channel.setCommand("su - gosst1 -c "pwd";");
  17. channel.connect();
  18.  
  19. String msg=null;
  20. List<String> lines = new ArrayList<>();
  21. while((msg=in.readLine())!=null){
  22. System.out.println(msg);
  23. lines.add(msg);
  24. }
  25.  
  26. channel.disconnect();
  27. session.disconnect();
  28. } catch(Exception e){
  29. logger.fatal("Remote BTU Process FAILED" + e);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement