Created
April 8, 2013 08:39
-
-
Save j3lte/5335215 to your computer and use it in GitHub Desktop.
NodeJS simple ssh checker, want to make this work better in the future. This is just a simple implementation of SSH2-module from the npm registry
This file contains hidden or 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
| var Connection = require('ssh2'); | |
| var c = new Connection(); | |
| c.on('connect', function() { | |
| console.log('Connection :: connect'); | |
| }); | |
| c.on('ready', function() { | |
| console.log('Connection :: ready'); | |
| c.exec('uptime && echo && ps aux && echo && free', function(err, stream) { | |
| if (err) throw err; | |
| stream.on('data', function(data, extended) { | |
| console.log((extended === 'stderr' ? 'STDERR: ' : '') + data); | |
| }); | |
| stream.on('end', function() { | |
| console.log('Stream :: EOF'); | |
| }); | |
| stream.on('close', function() { | |
| console.log('Stream :: close'); | |
| }); | |
| stream.on('exit', function(code, signal) { | |
| console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal); | |
| c.end(); | |
| }); | |
| }); | |
| }); | |
| c.on('error', function(err) { | |
| console.log('Connection :: error :: ' + err); | |
| }); | |
| c.on('end', function() { | |
| console.log('Connection :: end'); | |
| }); | |
| c.on('close', function(had_error) { | |
| console.log('Connection :: close'); | |
| }); | |
| c.connect({ | |
| host: 'xxx.xxx.xxx.xxx', | |
| port: 22, | |
| username: 'root', | |
| privateKey: require('fs').readFileSync('id_rsa'), | |
| passphrase : 'password' | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment