npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

remote-exec-2

v0.0.4

Published

Execute shell commands on one or more remote computers via SSH

Downloads

60

Readme

remote-exec

Very simple wrapper for ssh2 to execute shell commands on one or more remote computers in node via SSH

install

npm install remote-exec

usage

var rexec = require('remote-exec');
rexec(hosts <string|array>, commands <string|array>, options <object>, callback <function>);

hosts

hosts can be a string, an array of strings, or an array of objects
if hosts is an array of objects, the name key of each object will be used to connect to the host

commands

commands can be a string or an array of strings
commands can also contain parameters using the {{myParameter}} syntax (see below)

options

options is the connection options object used for ssh2 with the following additions:

  • the params key takes an object declaring global/default values for parameters used in commands
  • the beforeEach key takes a callback function run for each host before commands are run (passed host, commands, and params objects)
  • the afterEach key takes a callback function run for each host after commands are run or when an error is encountered (passed host, commands, params, and err objects)
  • stdout and/or stderr can be specified to change where output from the remote hosts is sent

examples

basic

var rexec = require('remote-exec');

// see documentation for the ssh2 npm package for a list of all options 
var connection_options = {
	port: 22,
	username: 'myuser',
	privateKey: require('fs').readFileSync('~/.ssh/rsa_id'),
	passphrase: 'mypassphrase'
};

var hosts = [
	'host1.somewhere.com',
	'host2.somewhere.else.com',
	'250.110.0.13'
];

var cmds = [
	'ls -l',
	'cat /etc/hosts'
];

rexec(hosts, cmds, connection_options, function(err){
	if (err) {
		console.log(err);
	} else {
		console.log('Great Success!!');
	}
});

parameters

// commands can be parameterized using the {{parameterName}} syntax
// parameters can be set at the global or host level

// global parameters should be set via the params key of the connections options
var connection_options = {
	port: 22,
	username: 'myuser',
	privateKey: require('fs').readFileSync('~/.ssh/rsa_id'),
	passphrase: 'mypassphrase',
	params: {
		myParam: 'something',
		anotherParam: 'something else'
	}
}

// to set a parameter for a specific host:
var hosts = [
	{name: 'host1.somewhere.com', myParam: 'this overrides the global myParam value', blah: 'this is an additional parameter at the host level'},
	{name: 'host2.somewhere.else.com'} // this host will only get the global parameters
];

var cmds = [
	'echo "{{myParam}}"'
];

rexec(hosts, cmds, connection_options, function(err){
	if (err) {
		console.log(err);
	} else {
		console.log('Great Success!!');
	}
});

output

// by default all output for remote computers is routed to process.stdout and process.stderr
// but this can be overridden by passing valid writable streams to the stdout and/or stderr
// keys of the connection options

var rexec = require('remote-exec')
  , fs = require('fs');

var connection_options = {
  port: 22,
  stdout: fs.createWriteStream('./out.txt'),
  stderr: fs.createWriteStream('./err.txt')
}

rexec('myserver.com', 'cat /proc/cpuinfo', connection_options);