I have a text blob that contains ip, port, user and passord and would like to write a small utility script where I can:
How would I launch the ssh command from node with the arguments, exit node and continue on ssh'ing? The documentation I've found regarding i.e. child_process concerns launching and controlling the process within node, but I simply want to exit back and take over once ssh is started.
The following code will fit your requirements, adjust it to your needs. The program does the following:
port
from a filestdin
ssh
using child_process.fork
Code:
var port = require('fs').readFileSync('port.txt');
const rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter hostname: ', (answer) => {
require('child_process').spawn('ssh', [answer, port],
{stdio: [process.stdin, process.stdout, process.stderr]});
});
The question is answered except for the following point:
exit node and continue on ssh'ing
I am not aware of this being possible in any programming language, but a better answer can correct me. Instead, you launch a child process and redirect all input/output to it. From your perspective, you only interact with ssh
, so the fact that the node
process still exists as a parent to ssh
is transparent to you.
An equivalent command in perl
for example would be system("ssh");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With