condor_submit
コンドル サーバーとの通信に SSH を使用していますが、カスタム コントロール用のコマンド ( 、condor_make
、condor_q
など)を呼び出す必要があります。Xcode プロジェクト (はい、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;
}
しかし、"ls -l"
を let's sayに置き換えると"condor_q"
、コマンドが実行されないようです。次のようなインタラクティブなシェルセッションを使用して、これを修正できました。
// 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 経由でカスタムコマンドを送信する簡単な方法はありますか?
ありがとう
マックス