hierynomus / hierynomus/sshj

How to stop executing commands that take too long

Open
#954 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.7k
Forks
620
Avg merge
3d 23h
Merged PRs (30d)
11

Description

```java
try {
sshClient = new SSHClient();
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect(host, port); // 连接到远程主机
sshClient.authPassword(username, password); // 使用密码进行身份验证
sshClient.setTimeout(timeout);
sshClient.setConnectTimeout(timeout);
} catch (IOException e) {
throw new RuntimeException(e);
}
```

```java
try {

Session.Command cmd = session.exec(cmdStr);

// 获取标准输出
String output = IOUtils.readFully(cmd.getInputStream()).toString();
log.debug("execute command output: {}", output);

// 获取错误输出
String errorOutput = IOUtils.readFully(cmd.getErrorStream()).toString();
if (errorOutput != null && !errorOutput.isEmpty()) {
log.debug("execute command error output: {}", output);
throw new CommandExecuteException(errorOutput);
}

cmd.join(this.timeout, TimeUnit.SECONDS);

session.close();
return output;

} catch (IOException e) {
throw new CommandExecuteException(e.getMessage());
}
```

How to stop executing commands that take too long???
```java
sshClient.setTimeout(timeout);
sshClient.setConnectTimeout(timeout);
cmd.join(this.timeout, TimeUnit.SECONDS);
```
None of them have taken effect

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.