java - How to execute Multiple commands -


i want to:

  1. log in putty using hostname, username, password , port number. have achieved.
  2. once logged in, want connect server1. in putty connect using ssh command (ssh user@server1).
  3. once connected server.i need run multiple commands like:

df -kh ps -ef|grep www

  1. and after executing above commands, need log out server1 , need log in server2.

how can in jsch?

jsch jsch=new jsch();  session session=jsch.getsession(remotehostusername, remotehostname, remotehostportno); session.setpassword(remotehostpassword);  properties config = new properties(); config.put("stricthostkeychecking", "no"); session.setconfig(config);  system.out.println("please wait..."); session.connect(); system.out.println("connected "+remotehostusername+"@"+remotehostname);  channelexec channel=(channelexec) session.openchannel("shell"); bufferedreader in=new bufferedreader(new inputstreamreader(channel.getinputstream()));  channel.setcommand("df -kh"); channel.setcommand("pwd"); channel.connect(); 

try channelshell channel = (channelshell) session.openchannel("shell"); setup inputstream , outputstream , subsequently perform following loop:

  • write connected inputstream , flush it
  • read connected outputstream

this way can construct second commands based on outcome of first one.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -