Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Prs72105 {
- public static void main(String[] args) {
- int k;
- Properties prop = new Properties();
- InputStream input = null;
- try {
- //input = new FileInputStream("./config/user.properties");
- input = new FileInputStream("src/user.properties");
- // load the properties file
- prop.load(input);
- } catch (IOException ex) {} finally {
- if (input != null) {
- try {
- input.close();
- } catch (IOException e) {}
- }
- }
- // get the property value and return it
- String host = "server host details";
- System.out.println("Server Name : " + host);
- System.out.println("Username : " + prop.getProperty("user").trim());
- String user = prop.getProperty("user").trim();
- String password = prop.getProperty("password").trim();
- //String command = "ls -al";
- String command = "cd /proj/was/logs/metrics; tail -f";
- //String command = "ls -al";
- try {
- k=0;
- java.util.Properties config = new java.util.Properties();
- config.put("StrictHostKeyChecking", "no");
- JSch jsch = new JSch();
- Session session = jsch.getSession(user, host, 22);
- session.setPassword(password);
- session.setConfig(config);
- session.connect();
- System.out.println("Connected");
- System.out.println("cd /proj/vista/was/logs/metrics");
- System.out.println("tail -f vista_interface_metrics.log vista_servlet_metrics.log vista_request_metrics.log;");
- System.out.println("");
- System.out.println("");
- Channel channel = session.openChannel("exec");
- //((ChannelExec)channel).setCommand(command1);
- ((ChannelExec) channel).setPty(true);
- ((ChannelExec) channel).setCommand(command);
- channel.setInputStream(null);
- ((ChannelExec) channel).setErrStream(System.err);
- InputStream in = channel.getInputStream();
- channel.connect();
- 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);
- k++;
- System.out.println("exit-status: "+ k);
- if(k==2){
- try {
- //Windows button is still pressed at this moment
- Robot r = new Robot();
- r.keyPress(KeyEvent.VK_CONTROL);
- r.keyPress(KeyEvent.VK_C);
- r.delay(1000);
- r.keyRelease(KeyEvent.VK_CONTROL);
- r.keyRelease(KeyEvent.VK_C);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }else
- {
- }
- } catch (Exception ee) {}
- }
- channel.disconnect();
- session.disconnect();
- System.out.println("DONE");
- } catch (Exception e) {}
- }
- }
Add Comment
Please, Sign In to add comment