Package at.molindo.esi4j.rebuild.util

Examples of at.molindo.esi4j.rebuild.util.BulkIndexHelper$Session


      if (isAuthenticated == false)
        throw new IOException("Authentication failed.");

      /* Create a session */

      Session sess = conn.openSession();

      sess.execCommand("uname -a && date && uptime && who");

      InputStream stdout = new StreamGobbler(sess.getStdout());
      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      System.out.println("Here is some information about the remote host:");

      while (true)
      {
        String line = br.readLine();
        if (line == null)
          break;
        System.out.println(line);
      }

      /* Close this session */

      sess.close();

      /* Close the connection */

      conn.close();

 
View Full Code Here


      if (isAuthenticated == false)
        throw new IOException("Authentication failed.");

      /* Create a session */

      Session sess = conn.openSession();

      sess.execCommand("uname -a && date && uptime && who");

      InputStream stdout = new StreamGobbler(sess.getStdout());

      BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

      System.out.println("Here is some information about the remote host:");

      while (true)
      {
        String line = br.readLine();
        if (line == null)
          break;
        System.out.println(line);
      }

      /* Close this session */
     
      sess.close();

      /* Close the connection */

      conn.close();

 
View Full Code Here

   * \return boolean
   *
   * @return
   */
  public boolean remoteIsWindowsShell() {
    Session objSSHSession = null;
    flgIsRemoteOSWindows = false;

    try {
      // TODO the testcommand should be defined by an option
      String checkShellCommand = "echo %ComSpec%";
      logger.debug("Opening new session...");
      objSSHSession = this.getSshConnection().openSession();
      logger.debug("Executing command " + checkShellCommand);
      objSSHSession.execCommand(checkShellCommand);

      logger.debug("output to stdout for remote command: " + checkShellCommand);
      ipsStdOut = new StreamGobbler(objSSHSession.getStdout());
      ipsStdErr = new StreamGobbler(objSSHSession.getStderr());
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(ipsStdOut));
      String stdOut = "";
      while (true) {
        String line = stdoutReader.readLine();
        if (line == null)
          break;
        logger.debug(line);
        stdOut += line;
      }
      logger.debug("output to stderr for remote command: " + checkShellCommand);
      BufferedReader stderrReader = new BufferedReader(new InputStreamReader(ipsStdErr));
      while (true) {
        String line = stderrReader.readLine();
        if (line == null)
          break;
        logger.debug(line);
      }
      // TODO The expected result-string for testing the os should be defined by an option
      if (stdOut.indexOf("cmd.exe") > -1) {
        logger.debug("Remote shell is a Windows shell.");
        flgIsRemoteOSWindows = true;
        return true;
      }
      else {
        logger.debug("Remote shell is a Linux/Unix shell.");
      }
    }
    catch (Exception e) {
      logger.debug("Failed to check if remote system is windows shell: " + e);
    }
    finally {
      if (objSSHSession != null)
        try {
          objSSHSession.close();
        }
        catch (Exception e) {
          logger.debug("Failed to close session: ", e);
        }
    }
View Full Code Here

    }

    public void cancelTheSession() {
        cancelIt = true;
        mSessionLock.lock();
        final Session thisSession;
        try {
            thisSession = sess;
            sess = null;
        } finally {
            mSessionLock.unlock();
        }
        if (thisSession != null) {
            thisSession.close();
        }
    }
View Full Code Here

    private void openSshSession(final ConnectionTimeout connectionTimeout)
            throws IOException {
        /* it may hang here if we lost connection, so it will be
         * interrupted after a timeout. */
        final Session newSession = connectionThread.getConnection().openSession();
        mSessionLock.lock();
        try {
            sess = newSession;
        } finally {
            mSessionLock.unlock();
View Full Code Here

        int exitCode = DEFAULT_EXIT_CODE;
        String outputString = "";
        try {
            mSessionLock.lock();
            final Session thisSession;
            try {
                thisSession = sess;
            } finally {
                mSessionLock.unlock();
            }
            if (thisSession == null) {
                return new SshOutput("", 130);
            }
            /* requestPTY mixes stdout and strerr together, but it works
            better at the moment.
            With pty, the sudo wouldn't work, because we don't want
            to enter sudo password by every command.
            (It would be exposed) */
            thisSession.requestPTY("dumb", 0, 0, 0, 0, null);
            LOG.debug2("execOneCommand: command: "
                       + host.getName()
                       + ": "
                       + host.getSudoCommand(host.getHoppedCommand(oneCommand), true));
            thisSession.execCommand("bash -c '"
                                    + Tools.escapeSingleQuotes("export LC_ALL=C;"
                                                               + host.getSudoCommand(host.getHoppedCommand(oneCommand),
                                                                                     false), 1) + '\'');
            outputString = execCommandAndCaptureOutput(oneCommand, thisSession);
            if (cancelIt) {
                return new SshOutput("", 130);
            }
            if (commandVisible) {
                host.getTerminalPanel().nextCommand();
            }
            thisSession.waitForCondition(ChannelCondition.EXIT_STATUS, 10000);
            final Integer ec = thisSession.getExitStatus();
            if (ec != null) {
                exitCode = ec;
            }
            thisSession.close();
            sess = null;
        } catch (final IOException e) {
            LOG.appWarning("execOneCommand: " + host.getName() + ':' + e.getMessage() + ':' + oneCommand);
            exitCode = ERROR_EXIT_CODE;
            cancelTheSession();
View Full Code Here

            boolean isAuthenticated = conn.authenticateWithPassword(this.user, this.password);
            if (isAuthenticated == false) {
                result.append("ERROR: Authentication Failed !");
            }

            Session session = conn.openSession();

            session.execCommand(cmd);
            BufferedReader read =
                    new BufferedReader(new InputStreamReader(new StreamGobbler(session.getStdout()), "GBK"));
            String line = "";
            while ((line = read.readLine()) != null) {
                result.append(line).append("\r\n");
            }
            session.close();
            conn.close();
            return result.toString();
        }
        catch (Throwable e) {
            throw new RemoteExecuteException("ִ���������", e);
View Full Code Here

    String get_ls() throws IOException {
        if (!conn.isAuthenticationComplete())
            throw new IOException("Authentication failed");

        Session session = conn.openSession();
        session.execCommand("ls -a");
        StreamGobbler stdout = new StreamGobbler(session.getStdout());

        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
        String out = br.readLine();

        session.close();

        return out;
    }
View Full Code Here

    String get_command(String command) throws IOException  {
        String response = null;
        if (!conn.isAuthenticationComplete())
            throw new IOException("Authentication failed");

        Session session = conn.openSession();
        session.execCommand(command);
        StreamGobbler stdout = new StreamGobbler(session.getStdout());

        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

        while (true) {
            String line = br.readLine();
            if (line == null)
                break;
            System.out.println(line);
        }

        session.close();

        return response;
    }
View Full Code Here

   * \return boolean
   *
   * @return
   */
  public boolean remoteIsWindowsShell() {
    Session objSSHSession = null;
    flgIsRemoteOSWindows = false;

    try {
      // TODO the testcommand should be defined by an option
      String checkShellCommand = "echo %ComSpec%";
      logger.debug("Opening new session...");
      objSSHSession = this.getSshConnection().openSession();
      logger.debug("Executing command " + checkShellCommand);
      objSSHSession.execCommand(checkShellCommand);

      logger.debug("output to stdout for remote command: " + checkShellCommand);
      ipsStdOut = new StreamGobbler(objSSHSession.getStdout());
      ipsStdErr = new StreamGobbler(objSSHSession.getStderr());
      BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(ipsStdOut));
      String stdOut = "";
      while (true) {
        String line = stdoutReader.readLine();
        if (line == null)
          break;
        logger.debug(line);
        stdOut += line;
      }
      logger.debug("output to stderr for remote command: " + checkShellCommand);
      BufferedReader stderrReader = new BufferedReader(new InputStreamReader(ipsStdErr));
      while (true) {
        String line = stderrReader.readLine();
        if (line == null)
          break;
        logger.debug(line);
      }
      // TODO The expected result-string for testing the os should be defined by an option
      if (stdOut.indexOf("cmd.exe") > -1) {
        logger.debug("Remote shell is a Windows shell.");
        flgIsRemoteOSWindows = true;
        return true;
      }
    }
    catch (Exception e) {
      logger.debug("Failed to check if remote system is windows shell: " + e);
    }
    finally {
      if (objSSHSession != null)
        try {
          objSSHSession.close();
        }
        catch (Exception e) {
          logger.debug("Failed to close session: ", e);
        }
    }
View Full Code Here

TOP

Related Classes of at.molindo.esi4j.rebuild.util.BulkIndexHelper$Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.