Guest User

Untitled

a guest
Aug 14th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. public class Prs72105 {
  2.  
  3.  
  4. public static void main(String[] args) {
  5.  
  6. int k;
  7.  
  8. Properties prop = new Properties();
  9. InputStream input = null;
  10.  
  11. try {
  12. //input = new FileInputStream("./config/user.properties");
  13. input = new FileInputStream("src/user.properties");
  14. // load the properties file
  15. prop.load(input);
  16.  
  17. } catch (IOException ex) {} finally {
  18. if (input != null) {
  19. try {
  20. input.close();
  21. } catch (IOException e) {}
  22. }
  23. }
  24. // get the property value and return it
  25.  
  26. String host = "server host details";
  27.  
  28. System.out.println("Server Name : " + host);
  29. System.out.println("Username : " + prop.getProperty("user").trim());
  30. String user = prop.getProperty("user").trim();
  31. String password = prop.getProperty("password").trim();
  32. //String command = "ls -al";
  33. String command = "cd /proj/was/logs/metrics; tail -f";
  34. //String command = "ls -al";
  35.  
  36. try {
  37. k=0;
  38. java.util.Properties config = new java.util.Properties();
  39. config.put("StrictHostKeyChecking", "no");
  40. JSch jsch = new JSch();
  41. Session session = jsch.getSession(user, host, 22);
  42. session.setPassword(password);
  43. session.setConfig(config);
  44. session.connect();
  45. System.out.println("Connected");
  46. System.out.println("cd /proj/vista/was/logs/metrics");
  47. System.out.println("tail -f vista_interface_metrics.log vista_servlet_metrics.log vista_request_metrics.log;");
  48. System.out.println("");
  49. System.out.println("");
  50. Channel channel = session.openChannel("exec");
  51. //((ChannelExec)channel).setCommand(command1);
  52. ((ChannelExec) channel).setPty(true);
  53. ((ChannelExec) channel).setCommand(command);
  54. channel.setInputStream(null);
  55. ((ChannelExec) channel).setErrStream(System.err);
  56.  
  57. InputStream in = channel.getInputStream();
  58.  
  59. channel.connect();
  60. byte[] tmp = new byte[1024];
  61. while (true) {
  62. while ( in .available() > 0) {
  63. int i = in .read(tmp, 0, 1024);
  64. if (i < 0) break;
  65.  
  66. System.out.print(new String(tmp, 0, i));
  67.  
  68. }
  69.  
  70. if (channel.isClosed()) {
  71. System.out.println("exit-status: " + channel.getExitStatus());
  72.  
  73. break;
  74. }
  75. try {
  76. Thread.sleep(1000);
  77. k++;
  78. System.out.println("exit-status: "+ k);
  79.  
  80. if(k==2){
  81.  
  82. try {
  83. //Windows button is still pressed at this moment
  84. Robot r = new Robot();
  85. r.keyPress(KeyEvent.VK_CONTROL);
  86. r.keyPress(KeyEvent.VK_C);
  87. r.delay(1000);
  88. r.keyRelease(KeyEvent.VK_CONTROL);
  89. r.keyRelease(KeyEvent.VK_C);
  90.  
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. }
  94.  
  95. }else
  96. {
  97.  
  98. }
  99.  
  100. } catch (Exception ee) {}
  101. }
  102. channel.disconnect();
  103. session.disconnect();
  104. System.out.println("DONE");
  105. } catch (Exception e) {}
  106.  
  107. }
  108. }
Add Comment
Please, Sign In to add comment