can i set timeout for ssh command?
sga8 opened this issue · 2 comments
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 ?
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
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