|  |  |  | @ -23,8 +23,8 @@ import ch.ethz.ssh2.*; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | public class GanymedSSH { | 
			
		
	
		
			
				
					|  |  |  |  | 	public static Logger log = Logger.getLogger(GanymedSSH.class); | 
			
		
	
		
			
				
					|  |  |  |  | 	 Connection conn; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	Connection conn; | 
			
		
	
		
			
				
					|  |  |  |  | 	public Map<String, Connection> otherConns; | 
			
		
	
		
			
				
					|  |  |  |  | 	public boolean status = true;// 锟角凤拷锟斤拷锟街达拷锟斤拷锟斤拷锟阶刺<E998B6>
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	public GanymedSSH() { | 
			
		
	
	
		
			
				
					|  |  |  | @ -44,22 +44,22 @@ public class GanymedSSH { | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	public  Connection getOpenedConnection(String host, String username, String password, int port) | 
			
		
	
		
			
				
					|  |  |  |  | 	public static Connection getOpenedConnection(String host, String username, String password, int port) | 
			
		
	
		
			
				
					|  |  |  |  | 			throws IOException { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 		conn = new Connection(host, port); | 
			
		
	
		
			
				
					|  |  |  |  | 		conn.connect(); // make sure the connection is opened
 | 
			
		
	
		
			
				
					|  |  |  |  | 		boolean isAuthenticated = conn.authenticateWithPassword(username, password); | 
			
		
	
		
			
				
					|  |  |  |  | 		Connection conns = new Connection(host, port); | 
			
		
	
		
			
				
					|  |  |  |  | 		conns.connect(); // make sure the connection is opened
 | 
			
		
	
		
			
				
					|  |  |  |  | 		boolean isAuthenticated = conns.authenticateWithPassword(username, password); | 
			
		
	
		
			
				
					|  |  |  |  | 		if (isAuthenticated == false) | 
			
		
	
		
			
				
					|  |  |  |  | 			throw new IOException("Authentication failed."); | 
			
		
	
		
			
				
					|  |  |  |  | 		return conn; | 
			
		
	
		
			
				
					|  |  |  |  | 		return conns; | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 	public  void execCmdNoWaitAcquiescent(String cmd) { | 
			
		
	
		
			
				
					|  |  |  |  | 		String host=Constant.hostIp; | 
			
		
	
		
			
				
					|  |  |  |  | 		String username=Constant.rootUser; | 
			
		
	
		
			
				
					|  |  |  |  | 		String password=Constant.rootPasswd; | 
			
		
	
		
			
				
					|  |  |  |  | 		int port=Constant.port; | 
			
		
	
		
			
				
					|  |  |  |  | //		String host=Constant.hostIp;
 | 
			
		
	
		
			
				
					|  |  |  |  | //		String username=Constant.rootUser;
 | 
			
		
	
		
			
				
					|  |  |  |  | //		String password=Constant.rootPasswd;
 | 
			
		
	
		
			
				
					|  |  |  |  | //		int port=Constant.port;
 | 
			
		
	
		
			
				
					|  |  |  |  | 		 | 
			
		
	
		
			
				
					|  |  |  |  | 		Session sess = null; | 
			
		
	
		
			
				
					|  |  |  |  | 		try { | 
			
		
	
	
		
			
				
					|  |  |  | @ -79,9 +79,16 @@ public class GanymedSSH { | 
			
		
	
		
			
				
					|  |  |  |  | 	public  void execCmdNoWait(String host, String username, String password, int port, String cmd) { | 
			
		
	
		
			
				
					|  |  |  |  | 		 | 
			
		
	
		
			
				
					|  |  |  |  | 		Session sess = null; | 
			
		
	
		
			
				
					|  |  |  |  | 		Connection new_conn; | 
			
		
	
		
			
				
					|  |  |  |  | 		try { | 
			
		
	
		
			
				
					|  |  |  |  | 			conn = getOpenedConnection(host, username, password, port); | 
			
		
	
		
			
				
					|  |  |  |  | 			sess = conn.openSession(); | 
			
		
	
		
			
				
					|  |  |  |  | 			if(otherConns.containsKey(host) && otherConns.get(host)!=null){ | 
			
		
	
		
			
				
					|  |  |  |  | 				 new_conn=otherConns.get(host); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			else{ | 
			
		
	
		
			
				
					|  |  |  |  | 				new_conn = getOpenedConnection(host, username, password, port); | 
			
		
	
		
			
				
					|  |  |  |  | 				otherConns.put(host, new_conn); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			sess = new_conn.openSession(); | 
			
		
	
		
			
				
					|  |  |  |  | 			// 执锟斤拷cmd
 | 
			
		
	
		
			
				
					|  |  |  |  | 			sess.execCommand(cmd); | 
			
		
	
		
			
				
					|  |  |  |  | 		} catch (IOException e) { | 
			
		
	
	
		
			
				
					|  |  |  | @ -94,10 +101,10 @@ public class GanymedSSH { | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	public  List<String> execCmdWaitAcquiescent(String cmd) { | 
			
		
	
		
			
				
					|  |  |  |  | 		String host=Constant.hostIp; | 
			
		
	
		
			
				
					|  |  |  |  | 		String username=Constant.rootUser; | 
			
		
	
		
			
				
					|  |  |  |  | 		String password=Constant.rootPasswd; | 
			
		
	
		
			
				
					|  |  |  |  | 		int port=Constant.port; | 
			
		
	
		
			
				
					|  |  |  |  | //		String host=Constant.hostIp;
 | 
			
		
	
		
			
				
					|  |  |  |  | //		String username=Constant.rootUser;
 | 
			
		
	
		
			
				
					|  |  |  |  | //		String password=Constant.rootPasswd;
 | 
			
		
	
		
			
				
					|  |  |  |  | //		int port=Constant.port;
 | 
			
		
	
		
			
				
					|  |  |  |  | 		List<String> reStrings = new ArrayList<String>(); | 
			
		
	
		
			
				
					|  |  |  |  | 		 | 
			
		
	
		
			
				
					|  |  |  |  | 		Session sess = null; | 
			
		
	
	
		
			
				
					|  |  |  | @ -148,9 +155,15 @@ public class GanymedSSH { | 
			
		
	
		
			
				
					|  |  |  |  | 		List<String> reStrings = new ArrayList<String>(); | 
			
		
	
		
			
				
					|  |  |  |  | 		 | 
			
		
	
		
			
				
					|  |  |  |  | 		Session sess = null; | 
			
		
	
		
			
				
					|  |  |  |  | 		Connection new_conn; | 
			
		
	
		
			
				
					|  |  |  |  | 		try { | 
			
		
	
		
			
				
					|  |  |  |  | 			 | 
			
		
	
		
			
				
					|  |  |  |  | 			sess = conn.openSession(); | 
			
		
	
		
			
				
					|  |  |  |  | 			if(otherConns.containsKey(host) && otherConns.get(host)!=null){ | 
			
		
	
		
			
				
					|  |  |  |  | 				 new_conn=otherConns.get(host); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			else{ | 
			
		
	
		
			
				
					|  |  |  |  | 				new_conn = getOpenedConnection(host, username, password, port); | 
			
		
	
		
			
				
					|  |  |  |  | 				otherConns.put(host, new_conn); | 
			
		
	
		
			
				
					|  |  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  |  | 			// 执锟斤拷cmd
 | 
			
		
	
		
			
				
					|  |  |  |  | 			sess.execCommand(cmd); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | 
 |