Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JSch jsch = new JSch();
- String user = "otc";
- String host = "p6-m1mp";
- String password = "mypassword"
- int port = 22;
- Session session = jsch.getSession(user, host, port);
- System.out.println("session created.");
- session.setConfig("StrictHostKeyChecking", "no");
- session.setPassword(password);
- session.connect();
- ChannelExec channel=(ChannelExec) session.openChannel("exec");
- BufferedReader in=new BufferedReader(new InputStreamReader(channel.getInputStream()));
- channel.setCommand("su - gosst1 -c "pwd";");
- channel.connect();
- String msg=null;
- List<String> lines = new ArrayList<>();
- while((msg=in.readLine())!=null){
- System.out.println(msg);
- lines.add(msg);
- }
- channel.disconnect();
- session.disconnect();
- } catch(Exception e){
- logger.fatal("Remote BTU Process FAILED" + e);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement