ssh username@hostIP in JSCh

Help
2010-05-14
2013-05-28
  • login as: hlwli2
    hlwli2@142.139.183.18's password:
    Last login: Fri May 14 08:04:28 2010 from 172.31.181.111
    Sun Microsystems Inc.   SunOS 5.9       Generic May 2002
    You have new mail.

    ===========================

    Environment Variables Set……

    ===========================
    hwhaqw4 hlwli2 $ssh roub11@10.157.21.122
    roub11@10.157.21.122's password:
    Last login: Thu May 13 15:40:54 2010 from hwhaqw4.nat.infy.com

    Are you authorised to use this computer as detailed above? (Y/N)?y
    /etc/profile: .: trap: condition(s) required

    Enterprise Linux Enterprise Linux Server release 5.3 (Carthage)

    BT Build OEL5-u3 v1.1 - March 2009

    rgh08102apg03 roub11 $ls -lrt

    These are the sequence of steps i'm performing in putty…
    Can i do this operation using JSch…
    This is the java code i tried…

    package objb;
    import com.jcraft.jsch.*;
    import java.io.*;

    public class Performance {
       
       
        public Performance() {
           
        }
        public static void main(String args) {
            JSch jsch = new JSch();
            try {
                   
                    Session session = jsch.getSession("hlwli2", "142.139.183.18", 22);
                 
                    java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no");
                    session.setConfig(config);
                    session.setPassword("pass");
                    session.connect();
                    Channel channel=session.openChannel("exec");      
                    ((ChannelExec)channel).setCommand("ssh roub11@10.157.21.122");
                    channel.setXForwarding(true);
                    channel.connect();
                    channel.setInputStream(System.in);
                    InputStream in = channel.getInputStream();
                    StringBuffer strb = new StringBuffer("");
                    byte tmp = new byte;
                    while (true)
                    {
                    while (in.available() > 0)
                    {
                    int i = in.read(tmp);
                    if (i < 0)
                    break;
                    System.out.print(new String(tmp, 0, i));
                    }
                    if (channel.isClosed())
                    {
                    in.close();
                    break;
                    }
                    }
                channel.disconnect();
                session.disconnect();
               
            }
            catch(Exception e) {
                e.printStackTrace();
               
            }
           
        }
    }

    But its not working…pls help me out…

     
  • These are the sequence of steps i'm performing in putty…
    login as: hlwli2
    hlwli2@142.139.183.18's password:
    Last login: Fri May 14 08:04:28 2010 from 172.31.181.111
    Sun Microsystems Inc.   SunOS 5.9       Generic May 2002
    You have new mail.

    ===========================

    Environment Variables Set……

    ===========================
    hwhaqw4 hlwli2 $ssh roub11@10.157.21.122
    roub11@10.157.21.122's password:
    Last login: Thu May 13 15:40:54 2010 from hwhaqw4.nat.infy.com

    Are you authorised to use this computer as detailed above? (Y/N)?y
    /etc/profile: .: trap: condition(s) required

    Enterprise Linux Enterprise Linux Server release 5.3 (Carthage)

    BT Build OEL5-u3 v1.1 - March 2009

    rgh08102apg03 roub11 $ls -lrt

    Can i do this operation using JSch…
    This is the java code i tried…

    package objb;
    import com.jcraft.jsch.*;
    import java.io.*;

    public class Performance {
       
       
        public Performance() {
           
        }
        public static void main(String args) {
            JSch jsch = new JSch();
            try {
                   
                    Session session = jsch.getSession("hlwli2", "142.139.183.18", 22);
                 
                    java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no");
                    session.setConfig(config);
                    session.setPassword("pass");
                    session.connect();
                    Channel channel=session.openChannel("exec");      
                    ((ChannelExec)channel).setCommand("ssh roub11@10.157.21.122");
                    channel.setXForwarding(true);
                    channel.connect();
                    channel.setInputStream(System.in);
                    InputStream in = channel.getInputStream();
                    StringBuffer strb = new StringBuffer("");
                    byte tmp = new byte;
                    while (true)
                    {
                    while (in.available() > 0)
                    {
                    int i = in.read(tmp);
                    if (i < 0)
                    break;
                    System.out.print(new String(tmp, 0, i));
                    }
                    if (channel.isClosed())
                    {
                    in.close();
                    break;
                    }
                    }
                channel.disconnect();
                session.disconnect();
               
            }
            catch(Exception e) {
                e.printStackTrace();
               
            }
           
        }
    }


    But its not working…pls help me out…