Created
January 19, 2019 00:31
-
-
Save YuriFontella/349fc93bbcf9477d422bc80ee37a065d to your computer and use it in GitHub Desktop.
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
'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