Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can i set timeout for ssh command? #465

Open
sga8 opened this issue May 13, 2023 · 2 comments
Open

can i set timeout for ssh command? #465

sga8 opened this issue May 13, 2023 · 2 comments
Labels

Comments

@sga8
Copy link

sga8 commented May 13, 2023

helllo.
i like node-ssh and i am using this library in our project.

I have a question about timeout.
when i use "execCommand" or "exec", how to set timeout ?

if i want to wait just 5 sec, how to set ?

@zydingjun
Copy link

zydingjun commented Jul 27, 2023

these demo may help you:

let timerID = setTimeout(()=>{
    console.log('sorry the timeout')
}, 5000)

ssh.execCommand('echo hello', {cwd:'/'}).then((result) => {
    console.log('nice, we got peer command output' + result.stdout)
}) .catch((err) => {
    console.log('something error')
}).finally(() => {
   clearTimeout(timerID)
   timerID = null
})

Edit by @steelbrain: Added formatting

@steelbrain
Copy link
Owner

Hi @sga8!

Thanks for writing in. Since this library is a wrapper around the ssh2 package, it supports the same features.

If you are using the exec or execCommand functions, it's not possible (as per my current knowledge) to issue an abort command. But depending on your usecase, you should be able to use the requestShell function, and invoke the command in the shell. Inside the shell, you can send various signals like ctrl-c through stdin.

If the commands you are executing are non consequential, you can do what @zydingjun recommended above and have a timeout in your local code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants