Description

rcmd (remote command) is a command line utility written in Ruby for executing the same command on multiple systems through ssh. This is done by assigning a host to a thread and creating the ssh sessions in those threads.

Features

  • Command line switch for setting number of threads to be used at a time. (Default is 4)
  • A comma seperated list of hosts piped from another command can be used as the node list.
  • Username can be specified. (Default is root. Requires valid ssh-key in ~/.ssh)
  • Output shows which host the output is from
  • Stdout can be suppressed, only allowing for stderr to be shown

Installation

rcmd is available as a gem and kan be installed with gem install rcmd

Usage Examples

Help Screen

Usage: rcmd [options]
    -u, --username username          Username for SSH connections
    -n, --nodes x,y,z                Comma seperated list of nodes. use '-' for a space seperated list piped from another command
    -r, --regexp regex               Use Regex to build host list (ruby regexp)
    -t, --threads threads            Number of threads to run
    -c, --command <command>          Quoted string containing the command to be run
    -q, --quiet                      Suppress stdout of commands.  stderr will still be displayed
    -v, --version                    Print what version of the command is in use
    -D, --debug                      Print debug information

Specifying nodes manually

Specifying a comma seperated list of hosts and timing the total execution time.

daibhidh@darkstar:~/$ time rcmd -n node1,node2,node3,node4 -c 'cat /etc/redhat-release'
node2 :: Red Hat Enterprise Linux ComputeNode release 6.8 (Santiago)
node1 :: Red Hat Enterprise Linux ComputeNode release 6.8 (Santiago)
node4 :: Red Hat Enterprise Linux ComputeNode release 6.9 (Santiago)
node3 :: Red Hat Enterprise Linux ComputeNode release 6.9 (Santiago)


real    0m2.749s
user    0m0.272s
sys     0m0.050s

Piping list of nodes

Using the hammer cli to get a list of hosts from a RedHat Satellite and providing it to rcmd as the node list.

daibhidh@darkstar:~/$ hammer --output base host list --organization org | awk '/Name:/ {print $2}' | rcmd -n - -c 'cat /etc/redhat-release'
node1.example.com :: Red Hat Enterprise Linux ComputeNode release 6.8 (Santiago)
node3.example.com :: Red Hat Enterprise Linux ComputeNode release 6.9 (Santiago)
node2.example.com :: Red Hat Enterprise Linux ComputeNode release 6.8 (Santiago)
node4.example.com :: Red Hat Enterprise Linux ComputeNode release 6.9 (Santiago)

Using regex to build node list

daibhidh@darkstar:~/$ rcmd -r 'node([1-9]|1[1-2])$' -c 'hostname -f'
node2 :: node2.example.com
node1 :: node1.example.com
node4 :: node4.example.com
node3 :: node3.example.com
node5 :: node5.example.com
node6 :: node6.example.com
node8 :: node8.example.com
node7 :: node7.example.com
node11 :: CONNECT ERROR :: Unable to connect to host!
node9 :: node9.example.com
node12 :: node12.example.com

Development

If you are wanting to modify the code by all means do so. If you clone this repository you can then run bundle install to install the dependencies needed. Tests are performed with rspec and can be run with rake.

Available Rake tasks are:

rake build            # Build rcmd-1.5.5.gem into the pkg directory
rake clean            # Remove any temporary products
rake clobber          # Remove any generated files
rake clobber_rdoc     # Remove RDoc HTML files
rake console          # Open an IRB console with this gem loaded
rake install          # Build and install rcmd-1.5.5.gem into system gems
rake install:local    # Build and install rcmd-1.5.5.gem into system gems without network access
rake rdoc             # Build RDoc HTML files
rake reinstall        # Remove, build, and install gem
rake release[remote]  # Create tag v1.5.5 and build and push rcmd-1.5.5.gem to Rubygems
rake rerdoc           # Rebuild RDoc HTML files
rake spec             # Run RSpec code examples