module.exports = function (config, done) { var ssh = new SimpleSSH({ host: config['vm-domain'], user: config['vm-usr'], pass: config['vm-pwd'] }), input = { type: 'list', name: 'version', message: 'Version' }; ssh.exec('ls -d ' + config.webroot + '/StoreTypes/*/', { out: function (response) { input.choices = response.match(/(?:\d{1,2}\.){2}\d{1,3}/g).reverse(); if (config.version !== undefined) { input.default = config.version; } done(input); } }).start(); };
robot.respond(/ark\sstart/i, function(res) { var ssh = new SSH(sshOptions); ssh.exec('pgrep ' + appToCheck, { exit: function(code, stdout) { if (code === 0) { res.reply('Server is already running.'); return false; } if (code === 1) { res.reply('Starting server!'); } } }) .exec('./'+process.env.ARKSTARTSCRIPT, { exit: function(code, stdout) { res.reply('Running ' + process.env.ARKSTARTSCRIPT); res.reply(stdout); res.reply('Server started. It takes approximately 4-6 minutes for the server to finish booting.'); } }) .start(); });
exports.handler = function(event, context, lambda) { console.log(event); // TODO use payload to configure ssh connection // TODO use payload to include commands to execute var ssh = new SSH({ host: '????', user: '******', key: '-----BEGIN RSA PRIVATE KEY-----\n' + '-----END RSA PRIVATE KEY-----' }); ssh .exec('pwd', { out: console.log.bind(console), exit: function() { ssh.exec('echo "new queue"', { out: console.log.bind(console), }); return false; } }) .on('error', function(err) { console.log(err); lambda(err); }) .on('ready', console.log.bind(console)) //.on('close', console.log.bind(console)) .start(); };
function tryLogin(serverHost, callback){ io.emit('server', { consoleData: "\nVerifying SSH connectivity to " + serverHost + "..." }); sshSession = new ssh({ host: serverHost, user: serverUsername, pass: serverPassword, key: serverKey, timeout: 5000 }); sshSession.on('error', function(err) { sshSession.end(); returnError(res, "\nServer validation failed: Could not connect to the server " + serverHost + " via SSH!"); }); sshSession.exec("echo '\nThis is a test command from Atomia!\n'", { out: function(stdout){ io.emit('server', { consoleData: stdout }); }, exit: function(code) { io.emit('server', { consoleData: "\nCommand completed with status code: " + code }); if(code == 0) finishedLoginCheck(); else returnError(res, "Server validation failed: Could not execute remot SSH command"); } }).start(); }
NODES.forEach(function(n){ console.log('--- connecting to', n); var ssh = new SSH({ host: n, user: '******', pass: '******', timeout: 30 * 1000 }); ssh.exec('reset-mcu', { out: function(stdout) { console.log(n, '- out:', stdout); }, err: function(stderr) { console.log(n, '- err:', stderr); }, exit: function(code) { console.log(n, '- exit with:', code); } }).start({ success: function() { console.log(n, '- connected:', n); }, fail: function() { console.log(n, '- failed:', n); } }); });
robot.respond(/ark\sstop/i, function(res) { var ssh = new SSH(sshOptions); ssh.exec('pgrep ' + appToCheck, { exit: function(code, stdout) { if (code === 0) { res.reply('Server is shutting down'); } if (code === 1) { res.reply('Server is not running'); return false; } } }) .exec('kill $(pgrep '+ appToCheck + ')', { exit: function(code, stdout, stderr) { if (code === 0) { res.reply('Server is shutdown'); } }, err: function(stderr) { res.reply('There was a problem shutting down the server. Error code: ' + stderr); } }) .start(); });
return new Promise((resolve, reject) => { ssh.exec( cmd, { out: (stdout) => console.log(stdout), err: (stderr) => console.error(stderr), } ). on('end', () => resolve()). start(); });
router.get('/ssh2', function (req, res, next) { var ssh = new SSH({ host: '192.168.0.12', user: '******', pass: '******' }); ssh.exec('/usr/local/hadoop/bin/hdfs dfs -put ~/Desktop/hello.html input', { exit: function () { res.send('success !'); } }).start(); });
client.scp('./routes/index.js', 'hadoop:secret@192.168.0.12:/home/hadoop/Desktop/', function (err) { if (err) { res.send(err); } else { var ssh = new SSH({ host: '192.168.0.12', user: '******', pass: '******' }); ssh.exec('/usr/local/hadoop/bin/hdfs dfs -put ~/Desktop/index.js input', { exit: function () { res.send('success !'); } }).start(); } })
robot.respond(/ark\sstatus/i, function(res) { var ssh = new SSH(sshOptions); ssh.exec('pgrep ' + appToCheck, { exit: function(code, stdout) { if (code === 0) { res.reply('The server is running. Game on!'); } if (code === 1) { res.reply('Sever is not running.'); } }, err: function(stderr) { res.repy(stderr); } }).start(); });
module.exports = function (config) { var deferred = Q.defer(); var end = new Date(); var ssh = new SSH(config); ssh.on('error', function(err) { console.log('Oops, something went wrong.'); console.log(err); ssh.end(); return deferred.reject(err); }); ssh.on('ready', function (){ end = new Date(); }); ssh.exec('pwd', { out: function(stdout) { console.log(stdout); }, exit: function(code, stdout, stderr) { // sudo mkswap /dev/xvdf // sudo swapon /dev/xvdf // yum -y install git // curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash // source ~/.bashrc // install ssh keys // install credentials // git clone // console.log(stdout); console.log(stderr); console.log(code); console.log("done"); ssh.end(); return deferred.resolve(end); } }).start(); return deferred.promise; };
module.exports = function (config, done) { var ignoredStores = ['Site', 'StoreCatalog', 'Storelib'], ssh = new SimpleSSH({ host: config['vm-domain'], user: config['vm-usr'], pass: config['vm-pwd'] }), input = { type: 'list', name: 'store', message: 'Store' }; ssh.exec('ls -d ' + config.webroot + '/StoreTypes/' + config.version + '/*/', { out: function (response) { var stores = [], storePaths = response.split('\n'); storePaths.pop(); storePaths.forEach(function (storePath) { var storeName = path.basename(storePath); if (ignoredStores.indexOf(storeName) > -1) { return; } stores.push(storeName); }); input.choices = stores; if (config.store !== undefined) { input.default = config.store; } done(input); } }).start(); };
function startConfigure(puppetHostname) { sshSession = new ssh({ host: serverHostname, user: serverUsername, pass: serverPassword, key: serverKey, timeout: 5000 }); sshSession.on('error', function(err) { sshSession.end(); io.emit('server', { consoleData: "Error communicating with the server: " + err }); }); sshSession.exec("sudo puppet agent --test --waitforcert 1", { out: function(stdout){ io.emit('server', { consoleData: stdout }); }, exit: function(code) { io.emit('server', { consoleData: code }); } }).start(); }
var sshPull = setInterval(function () { console.log('[SSH]---------- polling data'); ssh .exec("ubus -v call system board", { out: function(rxSSH) { try { mon.hardware = JSON.parse(rxSSH); } catch (e) { console.log('[ERR]---------- error parsing hardware data'); } console.log(mon.hardware); } }) .exec("ubus -v call system info", { out: function(rxSSH) { try { mon.system = JSON.parse(rxSSH); } catch (e) { console.log('[ERR]---------- error parsing system data'); } console.log(mon.system); } }) .exec("ubus -v call network.device status '{ \"name\": \"wlan0\" }'", { out: function(rxSSH) { try { mon.adhoc = JSON.parse(rxSSH); } catch (e) { console.log('[ERR]---------- error parsing adhoc data'); } console.log(mon.adhoc); } }) .start(); }, 20000); // run poll 1 every 30 seconds
Pull.getPull( hookid, branch, function(done){ if(!done.status && !done.data){ console.log("Repo and branch not foundin DB.", repo, branch); } else { var SSH = require('simple-ssh'); var ssh = new SSH({ host: done.data.serverip, user: done.data.serveruser, pass: done.data.serverpass }); ssh.exec("cd "+done.data.serverpath+" && "+done.data.command, { out: function(stdout) { console.log(stdout); }, err: function(stderr) { console.log(stderr); // this-does-not-exist: command not found } }).start(); } });
key: require('fs').readFileSync('/home/powerblade/.ssh/id_rsa_pb') }); console.log("Reading power and voltage values from load...") ssh.exec('./aps2/aps_3B12.py read', { out: function(stdout) { stdlist = stdout.replace('[','').replace(']','').replace('\n','').split(','); wave = parseFloat(stdlist[0]) voltage = parseFloat(stdlist[1]); wattage = parseFloat(stdlist[2]); if(wattage < 98 || wattage > 102 || wave != 0) { console.log("Wattage out of correct band, setting to 100 W...") ssh.exec('./aps2/aps_3B12.py 100', { out: function(stdout) { stdlist = stdout.replace('[','').replace(']','').replace('\n','').split(','); voltage = parseFloat(stdlist[0]); wattage = parseFloat(stdlist[1]); startScanningOnPowerOn(voltage, wattage, target_device); } }); } else { startScanningOnPowerOn(voltage, wattage, target_device); } } }).start(); } } if(server == false) {
/** * Execute command via SSH * @param {string} cmd - command to be executed * @param {object} options - options * @param {callback} cb - Callback on completion */ function sshExecCmd(cmd, options, cb) { var sshOptions = { host: config.device_host_name_or_ip_address, user: config.device_user_name, timeout: 30000 }; if (options.baseDir) { sshOptions.baseDir = options.baseDir; } var sshKey = findSshKey(); if (sshKey) { sshOptions.key = sshKey; } else if (config.device_password) { sshOptions.pass = config.device_password; } else { var err = new Error('No password or SSH key defined\nFailed command: ' + cmd); err.stack = err.message; cb(err); return; } var ssh = new simssh(sshOptions); ssh.on('error', function (e) { // when we pass error via deferred.reject, stack will be displayed // as it is just string, we can just replace it with message e.stack = 'ERROR: ' + e.message + '\nFailed command: ' + cmd; console.log('ERROR OCCURED'); cb(e); }); if (options && options.sshPrintCommands) { process.stdout.write(' SSH: ' + chalk.bgWhite.blue(' ' + cmd + ' ') + '\n'); } ssh.exec(cmd, { pty: true, out: function (o) { if (options && options.verbose) { process.stdout.write(o); } }, exit: function (code, stdout, stderr) { var succeeded = true; if (code != 0 || (options && options.marker && stdout.indexOf(options.marker) < 0)) { succeeded = false; } if (succeeded) { if (cb) cb(); } else { if (cb) { var message = `SSH command hasn\'t completed successfully.\nFailed command: ${cmd}\n` + (stdout ? `stdout: ${stdout}` : '') + (stderr ? `stderr: ${stderr}` : ''); var e = new Error(message); e.stack = message; cb(e); } } } }).start(); }
'use strict'; if(process.env.CIRCLE_BRANCH === 'circleci_angulartics'){ var SSH_USERNAME = process.env.DEV_SSH_USERNAME; var SSH_PASSWORD = process.env.DEV_SSH_PASSWORD; var SSH_HOST = process.env.DEV_SSH_HOST; var SSH = require('simple-ssh'); var ssh = new SSH({ host: SSH_HOST, user: SSH_USERNAME, pass: SSH_PASSWORD }); ssh .exec('cd /home/cbo/public', { out: console.log.bind(console) }) .exec('git pull origin develop', { out: console.log.bind(console) }) .exec('echo "DONE"', { exit: function(code) { process.exit(0); } }) .start(); } else { throw 'Not valid environment'; }
if(configuration && fs.statSync(configuration).isFile()){ // Read in the configuration above. configuration = JSON.parse(fs.readFileSync(configuration, "utf8")); } else { configuration = {}; } var starterAws = require('starter-aws'); ssh = new SSH({ host: SSH_HOST, user: SSH_USERNAME, pass: SSH_PASSWORD }); ssh .exec('cd /home/cbo/docker_'+branch+'/'+dockerName, { out: console.log.bind(console) }) .exec('git pull origin '+branch+'', { out: console.log.bind(console) }) .exec('docker build -t psesd/ssl-'+dockerName+':'+branch+' .', { out: console.log.bind(console) }) .exec('docker login -e "'+DOCKER_EMAIL+'" -u "'+DOCKER_USER+'" -p "'+DOCKER_PASS+'"', { out: console.log.bind(console) }) .exec('docker push psesd/ssl-'+dockerName+':'+branch+'', { out: console.log.bind(console) }) .exec('echo "DONE"', { exit: function(code) {
return new Promise(function (resolve, reject) { try { console.log(c.dim(cmd)); var ssh = new SSH({ host: host.host, user: host.username, timeout: conf.timeout, baseDir: host.path, agent: process.env.SSH_AUTH_SOCK, agentForward: true }); ssh.exec(cmd, { out: function (stdout) { process.stdout.write(stdout); }, err: function (stdout) { process.stdout.write(stdout); }, exit: function (code) { if (code != 0 || code != '0') { console.log(c.red.dim('command failed') + ', code ' + code); console.log(''); if (conf['stop-on-errors']) { reject(null); } else { // we don't stop on errors resolve(); } } else { resolve(); } return false; } }); ssh.on('error', function (err) { console.log(c.red.dim('an error has occured')); console.log(''); if (err.stack) { console.log(err.stack); console.log(''); } else { // non-stack error console.log(err); console.log(''); } ssh.end(); reject(null); }); ssh.start(); } catch (e) { reject(e); } });
exit: function() { ssh.exec('echo "new queue"', { out: console.log.bind(console), }); return false; }
var executeTask = function(task, callback) { if (task.type == 'backend') { // Format alternate version of tenant alias for backend scripts function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } var tenantParts = task.tenant.split('-'); tenantParts[0] = capitalizeFirstLetter(tenantParts[0]); tenantParts[1] = capitalizeFirstLetter(tenantParts[1]); camelCaseTenant = tenantParts.join(''); // Connect to VM using SSH key var ssh = new SSH({ host: config.vm.hostname, user: config.vm.username, key: config.vm.sshKey }); var formatOutput = function(output) { return ansi_up.ansi_to_html(output); }; ssh.exec("cd " + config.vm.basePath + " && " + task.script.replace(/{tenant}/, camelCaseTenant), { out: function(stdout) { callback({processing: true, output: formatOutput(stdout)}); console.log('stdout: ', stdout); }, err: function(stderr) { callback({processing: true, error: formatOutput(stderr)}); console.log('stderr: ', stderr); }, exit: function(code) { console.log('exit code: ' + code); ssh.end(); task.status = code === 0 ? true: false; callback(task); } }).start(); return task } else { const senchaOptions = task.script.replace(/{tenant}/, task.tenant).split(' '); const spawn = require('child_process').spawn; const command = spawn('sencha', senchaOptions, {cwd: config.webPath, env: process.env}); var bufferToString = function(buf) { return String.fromCharCode.apply(null, new Uint16Array(buf)); } command.stdout.on('data', function(data) { const stdout = bufferToString(data); callback({processing: true, output: stdout}); console.log('stdout: ' + stdout); }); command.stderr.on('data', function(data) { const stderr = bufferToString(stderr); callback({processing: true, error: stderr}); console.log('stderr: ' + stderr); }); command.on('error', function(error) { task.status = false; callback(task); console.log('Failed to start child process', error); }); command.on('close', function(code) { task.status = code === 0 ? true: false; callback(task); console.log('exit code: ' + code); }); } }
Private.find().exec(function(err,succ){ if(err) throw err.message; console.log(succ); for (var i = 0; i < succ.length; i++) { /*sails.log(succ.length, m); var host = succ[m].hostname, user = succ[m].username; sails.log(host, user);*/ var host = succ[i].hostname, user = succ[i].username; sails.log(host, user); var ssh = new SSH({ host: succ[i].hostname, port: succ[i].hostport, user: succ[i].hostuser, pass: succ[i].hostpassword }); console.log(ssh.host); ssh.exec('nproc', { out: function (cpucore) { console.log(cpucore) //global.cpucore = cpucore; fs.writeFile("/tmp/" + user + host + "cpucore", cpucore, function (err) { if (err) { console.log(err); } else { console.log("The file was saved!",host); } }); } }).exec('cat /proc/meminfo | grep MemTotal | cut -d":" -f2| cut -d"k" -f1|tr -d " "', { out: function (memtotal) { console.log(memtotal); fs.writeFile("/tmp/" + user + host + "memtotal", memtotal, function (err) { if (err) { console.log(err); } else { console.log("The file was saved!",host); } }); } }).exec('cat /proc/meminfo | grep MemFree | cut -d":" -f2| cut -d"k" -f1|tr -d " "', { out: function (memfree) { console.log(memfree); fs.writeFile("/tmp/" + user + host + "memfree", memfree, function (err) { if (err) { console.log(err); } else { console.log("The file was saved!",host); } }); } }).exec('uname -i', { out: function (arc) { console.log(arc); fs.writeFile("/tmp/" + user + host + "arc", arc, function (err) { if (err) { console.log(err); } else { console.log("The file was saved!",host); } }); } }).start(); fs.readFile("/tmp/" + user + host + "cpucore", 'utf8', function (err, cpucore) { if (err) { return console.log(err); } fs.readFile("/tmp/" + user + host + "memtotal", 'utf8', function (err, memtotal) { if (err) { return console.log(err); } fs.readFile("/tmp/" + user + host + "memfree", 'utf8', function (err, memfree) { if (err) { return console.log(err); } fs.readFile("/tmp/" + user + host + "arc", 'utf8', function (err, arctype) { if (err) { return console.log(err); } Resource.find({hostip: host}).exec(function (err, suc) { if (err) { sails.log(err.message); } else if (suc == "") { sails.log("This is Null"); Resource.create({username: user, hostip: host, cpu: cpucore, totalram: memtotal, leftram: memfree, arctype: arctype}).exec(function (err, succc) { if (err) { } else { sails.log("Data Created for ip", host); } }) } else { sails.log(suc); sails.log("We are here in Resources update function"); Resource.update({username: user, hostip: host}, {cpu: cpucore, totalram: memtotal, leftram: memfree, arctype: arctype}).exec(function (err, succc) { if (err) { } else { sails.log("Data Updated for ip", host); } }) } }) console.log(i); console.log(host, user, cpucore, memtotal, memfree, arctype); }) }) }) }) //console.log(host, user); console.log(i,"HEre"); } })