Created
July 20, 2021 09:26
-
-
Save palanisamym14/289242cc5371a74e61abb774edefb8e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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