Simplify running commands on multiple systems


To simplify scripting access to multiple machines, we present here a simple API that makes running commands on a POSIX compliant system, either local or remote, nothing short of a breeze.

Remote commands are run via ssh, and the aux binary can work as a proxy script, that enables an administrator to granulate access control.



On the machine you wish to control, you will probably want to use aux as a proxy script. This allows you to restrict client access to only pre specified commands. In this case you should just run:

npm install -g aux

###Client project

When using the aux library to control some machines from your application, just install as a dependency:

npm install aux



aux --user <username> --add-key <pub_key>
aux --user <username> --remove-key
aux [--user <username>] --add-command <command>
aux [--user <username>] --remove-command <command>

###Client project

var aux = require('aux');
aux.testing = new aux.Remote({host: ''});
aux.staging = new aux.Remote(
  {host: ''},
  {host: ''},
  {host: ''});
// optional callback with args: ({Error}, {Array}) 
aux.local('command', callback); 
aux.testing('command1', 'command2');
// if callback is provided, it is called when all servers have responded, with 
// args: ({Error}, {Array}) 
aux.staging('command', callback); 

##Usage example

As a contrived example, say we want enable the happy user, Fred, restart nginx on our Ubuntu server

  1. First we add Fred's public authentication key to our server
aux --user fred --add-key "ssh-rsa AAAA...=="
  1. Next we allow Fred to restart any service on the system
aux --user fred --add-command "sudo service \w+ restart"
  1. Create a simple script for Fred to use on his machine
var aux = require('aux');
aux.server = new aux.Remote({host: 'example.xom'});
aux.server('sudo service nginx restart', function (errresult) {
  if (err) throw err;

Now Fred can simply call this script to restart nginx on the server.

node restart_nginx.js