今天要做定時去linux取得資訊
但是有一兩個指令直接在terminal連線到linux可以正常
但是用程式跑的時候卻都是bash: xxxxx: command not found
JSch jsch = null;
jsch = new JSch();
Session session = jsch.getSession(userName, host);
if(port != null && port != 0) {
session.setPort(port);
}
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setTimeout(10000);
session.connect();
System.out.println("session = "+session.isConnected());
ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
InputStream in = channelExec.getInputStream();
channelExec.setCommand("lsnrctl help now");
channelExec.setErrStream(System.err);
channelExec.connect();
String out = IOUtils.toString(in, "UTF-8");
System.out.println("out = "+out);
channelExec.disconnect();
session.disconnect();