dacr / jassh

High level scala SSH API for easy and fast operations on remote servers.
Apache License 2.0
71 stars 27 forks source link

sudo hang #43

Open q1208c opened 2 months ago

q1208c commented 2 months ago

when try use 'become' run command with sudo, then program hang without any output or error. below is the code(some function).

    def runWithSudo(cmdString: String): (Boolean, String) = {
        log.info(
            s"run command '${cmdString}' with sudo on '${this.user}@${this.host}:${this.port}'"
            )
        val sshOptions         = this.sshOption()
        var runState : Boolean = false
        var runResult: String  = ""
        try {
            SSH.once(sshOptions) { ssh => {
                val (r1, r2) = ssh.shell { sh =>
                    sh.become("root") -> sh.execute(cmdString)
                }
                runState = r1
                runResult = r2
            }
            }
        } catch {
            case ex: Exception => log.error("SSHHost.runWithSudo", ex)
        }
        (runState, runResult)
    }

The SSHOption is only set user, host, port, all other is default.

I think there something wrong, what I can do? Thanks.

q1208c commented 2 months ago

Sorry, I lose some thing.

The user I used do not have right to use with sudo (in command line shell). Because this is the normal working case, some user have right with sudo, the other not, I try check the user have sudo right or not.