Skip to content

Instantly share code, notes, and snippets.

@YuriFontella
Created January 19, 2019 00:31
Show Gist options
  • Save YuriFontella/349fc93bbcf9477d422bc80ee37a065d to your computer and use it in GitHub Desktop.
Save YuriFontella/349fc93bbcf9477d422bc80ee37a065d to your computer and use it in GitHub Desktop.
'use strict'
const Connection = require('simple-ssh')
const crypto = require('../services/crypto')
exports.command = async (customer) => {
const ssh = new Connection({
host: customer.ip,
user: customer.user,
pass: crypto.decrypt(customer.password),
port: customer.port
})
return new Promise((resolve, reject) => {
ssh.exec('ping 8.8.8.8 -c 6', {
exit: async (code) => {
if (code === 1) {
// comando errado
} else if (code === 0) {
// executado com sucesso
} else if (code === 127) {
// comando inválido
}
},
out: function (stdout) {
// saída do comando
}
}).on('error', function (err) {
// não conectou
ssh.end()
}).start()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment