Package ch.ethz.ssh2

Examples of ch.ethz.ssh2.Session


                if (i % 10 == 0)
                    linuxCommand = "rm -rf *; wget http://" + downloadUrl + " && ls -al dump.bin";
                else
                    linuxCommand = "wget http://" + downloadUrl + " && ls -al dump.bin";

                Session sess = conn.openSession();
                s_logger.info("User " + s_account.get() + " executing : " + linuxCommand);
                sess.execCommand(linuxCommand);

                InputStream stdout = sess.getStdout();
                InputStream stderr = sess.getStderr();

                byte[] buffer = new byte[8192];
                while (true) {
                    if ((stdout.available() == 0) && (stderr.available() == 0)) {
                        int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);

                        if ((conditions & ChannelCondition.TIMEOUT) != 0) {
                            s_logger.info("Timeout while waiting for data from peer.");
                            return null;
                        }

                        if ((conditions & ChannelCondition.EOF) != 0) {
                            if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                                break;
                            }
                        }
                    }

                    while (stdout.available() > 0) {
                        success = true;
                        int len = stdout.read(buffer);
                        if (len > 0) // this check is somewhat paranoid
                            s_logger.info(new String(buffer, 0, len));
                    }

                    while (stderr.available() > 0) {
                        /* int len = */stderr.read(buffer);
                    }
                }

                sess.close();
                conn.close();

                if (!success) {
                    retry++;
                    if (retry == MAX_RETRY_LINUX) {
View Full Code Here


        if (logger.isLoggable(Level.FINER)) {
            logger.finer("Running command " + command + " on host: " + this.host);
        }

        openConnection();
        final Session sess = connection.openSession();

        int status = exec(sess, command, os, listInputStream(stdinLines));

        // XXX: Should we close connection after each command or cache it
        // and re-use it?
View Full Code Here

        if (logger.isLoggable(Level.FINER)) {
            logger.finer("Running command " + command + " on host: " + this.host);
        }

        openConnection();
        final Session sess = connection.openSession();

        int status = exec(sess, command, os, listInputStream(stdinLines));

        // XXX: Should we close connection after each command or cache it
        // and re-use it?
View Full Code Here

        }

        openConnection();
        StringBuffer buff = new StringBuffer();
        if (env != null) {
            Session tempSession = connection.openSession();
            OutputStream ous = new ByteArrayOutputStream();
            exec(tempSession, "ps -p $$ | tail -1 | awk '{print $NF}'", ous, null);
            String prefix;
            if (ous.toString().contains("csh")) {
                logger.fine("CSH shell");
                prefix = "setenv";
            } else {
                logger.fine("BASH shell");
                prefix = "export";
            }
            for (String st : env) {
                String cmd = prefix + " " + st;
                buff.append(cmd).append(";");
            }
        }
        buff.append(command);
        final Session sess = connection.openSession();
        int status = exec(sess, buff.toString(), os, listInputStream(stdinLines));

        // XXX: Should we close connection after each command or cache it
        // and re-use it?
        SSHUtil.unregister(connection);
View Full Code Here

        }
       
        public Session openSession() throws IOException {
            lock(Thread.currentThread());
            try {
                Session session = myConnection.openSession();
                if (session != null) {
                    mySessionCount++;
                }
                SVNDebugLog.getDefaultLog().logFine(SVNLogType.NETWORK,
                        ourRequestor + ": SESSION OPENED: " + this + "." + mySessionCount);
View Full Code Here

        if (logger.isLoggable(Level.FINER)) {
            logger.finer("Running command " + command + " on host: " + this.host);
        }

        openConnection();
        final Session sess = connection.openSession();

        int status = exec(sess, command, os, listInputStream(stdinLines));

        // XXX: Should we close connection after each command or cache it
        // and re-use it?
View Full Code Here

        }

        openConnection();
        StringBuffer buff = new StringBuffer();
        if (env != null) {
            Session tempSession = connection.openSession();
            OutputStream ous = new ByteArrayOutputStream();
            exec(tempSession, "ps -p $$ | tail -1 | awk '{print $NF}'", ous, null);
            String prefix;
            if (ous.toString().contains("csh")) {
                logger.fine("CSH shell");
                prefix = "setenv";
            } else {
                logger.fine("BASH shell");
                prefix = "export";
            }
            for (String st : env) {
                String cmd = prefix + " " + st;
                buff.append(cmd).append(";");
            }
        }
        buff.append(command);
        final Session sess = connection.openSession();
        int status = exec(sess, buff.toString(), os, listInputStream(stdinLines));

        // XXX: Should we close connection after each command or cache it
        // and re-use it?
        SSHUtil.unregister(connection);
View Full Code Here

        if (logger.isLoggable(Level.FINER)) {
            logger.finer("Running command " + command + " on host: " + this.host);
        }

        openConnection();
        final Session sess = connection.openSession();

        int status = exec(sess, command, os, listInputStream(stdinLines));

        // XXX: Should we close connection after each command or cache it
        // and re-use it?
View Full Code Here

        if (logger.isLoggable(Level.FINER)) {
            logger.finer("Running command " + command + " on host: " + this.host);
        }

        openConnection();
        final Session sess = connection.openSession();

        int status = exec(sess, command, os, listInputStream(stdinLines));

        // XXX: Should we close connection after each command or cache it
        // and re-use it?
View Full Code Here

        if (logger.isLoggable(Level.FINER)) {
            logger.finer("Running command " + command + " on host: " + this.host);
        }

        openConnection();
        final Session sess = connection.openSession();

        int status = exec(sess, command, os, listInputStream(stdinLines));

        // XXX: Should we close connection after each command or cache it
        // and re-use it?
View Full Code Here

TOP

Related Classes of ch.ethz.ssh2.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.