콘돔 서버와 통신하는 데 SSH를 사용하고 있으며 사용자 정의 제어 (예 : condor_submit
, condor_make
, condor_q
등) 명령을 호출해야합니다. 내 Xcode 프로젝트에서 libSSH를 다운로드하여 성공적으로 통합 한 경우 (예, Mac OS 사용) 제공된 기능이 사용자 정의 명령을 지원하지 않음을 발견했습니다.libssh의 사용자 정의 명령
rc = ssh_channel_request_exec(channel, "ls -l");
if (rc != SSH_OK) {
ssh_channel_close(channel);
ssh_channel_free(channel);
return rc;
}
을하지만 내가 명령을 실행하지 않는 것의이 "condor_q"
을 가정 해 봅시다과 "ls -l"
를 교체 할 때 : 튜토리얼이 호스트에서 명령을 실행할 것이라고 말했다. 내가 지금처럼 대화 형 쉘 세션을 사용하여이 문제를 해결하기 위해 관리 :
// Create channel
rc = ssh_channel_request_pty(channel);
if (rc != SSH_OK) return rc;
rc = ssh_channel_change_pty_size(channel, 84, 20);
if (rc != SSH_OK) return rc;
rc = ssh_channel_request_shell(channel);
std::string commandString = "condor_q";
char buffer[512];
int bytesRead, bytesWrittenToConsole;
std::string string;
while (ssh_channel_is_open(channel) && !ssh_channel_is_eof(channel)) {
// _nonblocking
bytesRead = ssh_channel_read_nonblocking(channel, buffer, sizeof(buffer), 0);
if (bytesRead < 0) {
rc = SSH_ERROR;
break;
}
if (bytesRead > 0) {
for (int i = 0; i < bytesRead; i++) {
string.push_back(buffer[i]);
}
bytesWrittenToConsole = write(1, buffer, bytesRead);
if (string.find("$") != std::string::npos) {
if (commandString.length() > 0) {
ssh_channel_write(channel, commandString.c_str(), commandString.length());
ssh_channel_write(channel, "\n", 1);
} else {
break;
}
commandString.clear();
string.clear();
}
}
}
// Distroy channel
그래서 내 질문에, 오히려 " 가짜-보내기"를하는 것보다 SSH를 통해 사용자 정의 명령을 보낼 수있는 쉬운 방법이있다 명령?
감사
최대
예제 파일에는 튜토리얼 코드와 매우 유사한 코드가 포함되어 있으므로 큰 도움이되지 않습니다. (그러나 여전히 출력을 기다릴 필요가 있지만 ssh 채널을 계속 읽는 루프를 실행할 때는 아무 것도하지 않습니다. 또한 내 코드에 게시 한 소스를 확인 했습니까? 귀하가 게시 한 링크와 동일합니다.) –
내가 성공적으로 실행되었는지 확인 했으므로 종료 코드를 확인해야합니다. ssh_channel_request_exec()의 리턴 코드는 서버에 성공적으로 전송되었음을 알려줍니다. 서버는 종료 코드를 사용하여 서버를 성공적으로 실행했는지 알려줍니다. 인터랙티브 쉘은 다음과 같이 자신의 프로토콜을 사용하는 것이 더 좋습니다. ls && echo OK || 에코 KO – asn