node-ssh
node-ssh copied to clipboard
How do I run dd with sudo?
I run the following code: ssh.exec( 'sudo -S dd if=/mnt/storage/disks/other6 of=/mnt/storage/disks/other7', ['status=progress'], { execOptions: { pty: true }, stdin: '1234', onStdout(chunk) { console.log('stdoutChunk', chunk.toString()); }, onStderr(chunk) { console.log('stderrChunk', chunk.toString()); }, }, ); And everything hangs on this output: hello stdoutChunk 1234 stdoutChunk Password:
Try use ‘root’ user. Or Configure password-free on the target host when you use ‘sudo’ command. This is my way, If there is a better way, please let me know.
About six years ago, I wrote a small tool to help with this, https://github.com/steelbrain/Expected-Write
It's not maintained tho, but you get the idea. Request a shell, execute the command, when you get the password prompt, write to the shell