1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
try {
final JSch jsch = new JSch();
String host = null;
host = JOptionPane.showInputDialog("Enter username@hostname",
"oracle@" + ConfigGlobaleUtils.getInstance().getAdresseDatabase());
final String user = host.substring(0, host.indexOf('@'));
host = host.substring(host.indexOf('@') + 1);
final Session session = jsch.getSession(user, host, 22);
// username and password will be given via UserInfo interface.
final UserInfo ui = new MyUserInfo();
session.setUserInfo(ui);
session.connect();
final String command = JOptionPane.showInputDialog("Enter command",
"./deployDev/manueldeploy.sh " + ConfigGlobaleUtils.getInstance().getLoginDatabase());
final Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
// channel.setInputStream(null);
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
((ChannelExec) channel).setErrStream(System.err);
final InputStream in = channel.getInputStream();
channel.connect();
final byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
final int i = in.read(tmp, 0, 1024);
if (i < 0) {
break;
}
System.out.print(new String(tmp, 0, i));
}
if (channel.isClosed()) {
System.out.println("exit-status: "
+ channel.getExitStatus());
break;
}
try {
Thread.sleep(1000);
} catch (final Exception ee) {
}
}
channel.disconnect();
session.disconnect();
} catch (final Exception e) {
System.out.println(e);
} |
Partager