目前参照以下方法成功执行一条命令,但是。。。。。 需要多条执行,而且是在前一条的基础上!!百度有说用分号隔开,本鸟执行一下,完全卡主不动了就。。。。
本人菜鸟一枚,希望大神们不吝赐教
String command="hdfs dfs -put -f "+basePath + labelFilePath+" /user/hive/warehouse/dmp.db/saas_id_mapping_helper;"
public static String sshExecute(String host, String user, String pwd,
String command) {
StringBuffer sb = new StringBuffer();
try {
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
session.setPassword(pwd);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
InputStream in = channel.getInputStream();
channel.connect();
int nextChar;
while (true) {
while ((nextChar = in.read()) != -1) {
sb.append((char) nextChar);
}
if (channel.isClosed()) {
System.out.println("exit-status: "
+ channel.getExitStatus());
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
}
}
channel.disconnect();
session.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}