Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import java.io.InputStream;
  2. import com.jcraft.jsch.Channel;
  3. import com.jcraft.jsch.ChannelExec;
  4. import com.jcraft.jsch.JSch;
  5. import com.jcraft.jsch.Session;
  6. import java.util.Properties;
  7.  
  8. public class ShellExecuter {
  9.  
  10. /**
  11. * @param args
  12. */
  13. public static void main(String[] args) {
  14. String host = "10.111.111.11";
  15. String user = "username";
  16. String password = "password";
  17. String FND_TOP = "/u01/oracle/fs1/appl/fnd/12.0.0";
  18. String command = "FNDLOAD user/pass O Y DOWNLOAD " + FND_TOP + "/patch/115/import/abc.lct "
  19. + "/home/applvis/JAVA/abc.ldt PROGRAM APPLICATION_SHORT_NAME=XX "
  20. + "CONCURRENT_PROGRAM_NAME=UPLOAD_TOOL";
  21. try {
  22.  
  23. Properties config = new Properties();
  24. config.put("StrictHostKeyChecking", "no");
  25. JSch jsch = new JSch();
  26. Session session = jsch.getSession(user, host, 22);
  27. session.setPassword(password);
  28. session.setConfig(config);
  29. session.connect();
  30. System.out.println("Connected");
  31.  
  32. Channel channel = session.openChannel("exec");
  33. ((ChannelExec) channel).setCommand(command);
  34. channel.setInputStream(null);
  35. ((ChannelExec) channel).setErrStream(System.err);
  36.  
  37. InputStream in = channel.getInputStream();
  38. channel.connect();
  39. byte[] tmp = new byte[1024];
  40. while (true) {
  41. while (in.available() > 0) {
  42. int i = in.read(tmp, 0, 1024);
  43. if (i < 0) {
  44. break;
  45. }
  46. System.out.print(new String(tmp, 0, i));
  47. }
  48. if (channel.isClosed()) {
  49. System.out.println("exit-status: " + channel.getExitStatus());
  50. break;
  51. }
  52. try {
  53. Thread.sleep(1000);
  54. } catch (Exception ee) {
  55. }
  56. }
  57. channel.disconnect();
  58. session.disconnect();
  59. System.out.println("DONE");
  60. } catch (Exception e) {
  61. e.printStackTrace();
  62. }
  63.  
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement