원격 서버에서 .csh 스크립트를 실행하기 위해 Jsch를 사용하려고합니다. 나는 cp, mv, ls와 같은 명령을 실행할 수있다. 그러나 일부 환경 변수를 내부적으로 참조하는 스크립트를 실행하려고하면 스크립트는 상태 1로 종료됩니다. exec.exec을 사용하여 실행할 때 액세스 할 수없는 script.sh 내에서 INTERNAL_ENV_VARIABLE이 참조됩니다. 이 종속성을 처리 할 exec에서 .csh 스크립트를 실행할 수있는 방법이 있습니까?jsch 라이브러리를 사용하여 .csh 스크립트를 실행할 수 없습니다. - Exit 1
exec 대신 셸을 사용하는 것은 옵션이 아닙니다. 셸을 열 때 여러 인증 수준이 있고 여러 자격 증명에 따라 우리가 개발중인 테스트 프레임 워크를 만들기 때문입니다.
명령 스크립트 디렉토리로 이동하여 스크립트를 실행하려고합니다.
는util.executeCommand(session,"cd " + script directory+";"+"./script.csh");
는 콘솔 출력 명령을 실행
[email protected]
INTERNAL_ENV_VARIABLE: Undefined variable.
exit-status: 1
방법 : 세션을 생성하는
public int executeCommand(Session session, String script) throws JSchException, IOException {
System.out.println("Execute Script " + script);
ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
((ChannelExec)channelExec).setPty(true);
InputStream in = channelExec.getInputStream();
channelExec.setInputStream(null);
channelExec.setErrStream(System.err);
channelExec.setCommand(script);
channelExec.connect();
byte[] tmp = new byte[1024];
while (true) {
while (in.available() > 0) {
int i = in.read(tmp, 0, 1024);
System.out.println(channelExec.getErrStream());
if (i < 0)
break;
System.out.print(new String(tmp, 0, i));
}
if (channelExec.isClosed()) {
System.out.println("exit-status: " + channelExec.getExitStatus());
break;
}
try {
Thread.sleep(1000);
} catch (Exception ee) {
System.out.println(ee);
}
}
channelExec.disconnect();
return channelExec.getExitStatus();
}
방법 ExecuteCommand를 : createSession를
public Session createSession(String user, String host, int Port, String Password) throws JSchException {
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, Port);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(Password);
session.connect(5000);
System.out.println(session.isConnected());
return session;
}
}
, 당신은 새로운 질문을 요청해야합니다. 기존 질문을 완전히 다른 것으로 바꾸고 기존 답변을 쓸모 없게 만들지 말아야합니다. [누군가 내 질문에 대답 할 때 무엇을해야합니까?] (https://stackoverflow.com/help/someone-answers) – Kenster
죄송합니다. 나는 신입이다. 나는 지금까지 한 일을 깨닫는다. 그러나 나는 그 질문을 올바르게 얻으려고 노력하고 있었다. – njosep
새로운 문제는 [JSch : 사용자 환경 변수를 "exec"채널에 표시하는 방법이 있습니까?] (https://stackoverflow.com/a/46350885/850848) –