Skip to content

Instantly share code, notes, and snippets.

@palanisamym14
Created July 20, 2021 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palanisamym14/289242cc5371a74e61abb774edefb8e1 to your computer and use it in GitHub Desktop.
Save palanisamym14/289242cc5371a74e61abb774edefb8e1 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const { Client } = require('ssh2');
const run = async () => {
try {
return new Promise((resolve, reject) => {
const conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
console.log('Client :: ready');
conn.shell( (err, stream) => {
if (err) throw console.log(err);
stream.on('close', () => {
console.log('Stream :: close');
conn.end();
}).on('data', (data) => {
console.log('OUTPUT: ' + data);
}).on('exit', (data) => {
console.log(data, 'err');
}).on('error', (data) => {
console.log('error: ' + data);
}).stderr.on('data', (data) => {
console.log('STDERR: ' + data);
})
stream.end('sh /home/ubuntu/shell-test/temp.sh\nexit\n');
});
}).connect({
host: '',
port: '22',
username: 'ubuntu',
privateKey: fs.readFileSync('./id_rsa')
})
})
} catch (error) {
console.log(error)
}
}
(async () => await run())()
{"mode":"full","isActive":false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment