NAME

SSH::Batch - Cluster operations based on parallel SSH, set and interval arithmetic

Table of Contents

VERSION

This document describes SSH::Batch 0.030 released on 8 November 2015.

SYNOPSIS

The following scripts are provided:

DESCRIPTION

System administration (sysadmin) is also part of my $work. Playing with a (big) bunch of machines without a handy tool is painful. So I refactored some of our old scripts and hence this module.

This is a high-level abstraction over the powerful Net::OpenSSH module. A bunch of handy scripts are provided to simplify big cluster operations: fornodes, atnodes, tonodes, and key2nodes.

SSH::Batch allows you to name your clusters using variables and interval/set syntax in your ~/.fornodesrc config file (or a different file name specified by the SSH_BATCH_RC environment). For instance:

$ cat ~/.fornodesrc
A=foo[01-03].com bar.org
B=bar.org baz[a-b,d,e-g].cn foo02.com
C={A} * {B}
D={A} - {B}

where cluster C is the intersection set of cluster A and B while D is the sef of machines that are in A but not in B.

And then you can query machine host list by using SSH::Batch's fornodes script:

$ fornodes '{C}'
bar.org foo02.com

$ fornodes '{D}'
foo01.com foo03.com

$ fornodes blah.com '{C} + {D}'
bar.org blah.com foo01.com foo02.com foo03.com

It's always best practice to put spaces around set operators like +, -, *, and /, so as to allow these characters (notably the dash -) in your host names, as in:

$ fornodes 'foo-bar-[a-d].com - foo-bar-c.com'
foo-bar-a.com foo-bar-b.com foo-bar-d.com

for the ranges like [a-z], there's also an alternative syntax:

[a..z]

To exclude some discrete values from certain range, you need set subtration:

foo[1-100].com - foo[32,56].com

or equivalently

foo[1-31,33-55,57-100].com

fornodes could be very handy in shell programming. For example, to test the 80 port HTTP service of a cluster A, simply put

$ for node in `fornodes '{A}'`; \
    do curl "http://$node:80/blah'; \
  done

Also, other scripts in this module, like atnodes, tonodes, and key2nodes also call fornodes internally so that you can use the cluster spec syntax in those scripts' command line as well.

atnodes meets the common requirement of running a command on a remote cluster. For example:

# at the concurrency level of 6:
atnodes 'ls -lh' '{A} + {B}' my.more.com -c 6

Or upload a local file to the remote cluster:

tonodes ~/my.tar.gz '{A} / {B}' :/tmp/

or multiple files as well as some directories:

tonodes -r ~/mydir ~/mydir2/*.so -- foo.com bar.cn :~/

It's also possible to use wildcards in the cluster spec expression, as in

atnodes 'ls ~' 'api??.*.com'

where atnodes will match the pattern api??.*.com against the "universal set" consisting of those hosts appeared in ~/fornodesrc and those host names apeared before this pattern on the command line (if any). Note that only ? (match any character) and * (match 0 or more characters) are supported here.

There's also a key2nodes script to push SSH public keys to remote machines ;)

Back to TOC

TIPS

There's some extra tips found in our own's everyday use:

Back to TOC

PREREQUISITES

This module uses Net::OpenSSH behind the scene, so it requires the OpenSSH client executable (usually spelled "ssh") with multiplexing support (at least OpenSSH 4.1). To check your ssh version, use the command:

$ ssh -v

On my machine, it echos

OpenSSH_4.7p1 Debian-8ubuntu1.2, OpenSSL 0.9.8g 19 Oct 2007
usage: ssh [-1246AaCfgKkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-e escape_char] [-F configfile]
           [-i identity_file] [-L [bind_address:]port:host:hostport]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R [bind_address:]port:host:hostport] [-S ctl_path]
           [-w local_tun[:remote_tun]] [user@]hostname [command]

There's no spesial requirement on the server side ssh service. Even a non-OpenSSH server-side deamon should work as well.

Back to TOC

INSTALLATION

perl Makefile.PL
make
make test
sudo make install

Win32 users should replace "make" with "nmake".

Back to TOC

CODE REPOSITORY

You can always get the latest SSH::Batch source from its public Git repository:

http://github.com/agentzh/sshbatch

If you have a branch for me to pull, please let me know ;)

Back to TOC

TODO

Back to TOC

AUTHORS

Back to TOC

COPYRIGHT & LICENSE

This module as well as its programs are licensed under the BSD License.

Copyright (C) 2009-2015, Yichun "agentzh" Zhang (章亦春). All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Back to TOC

SEE ALSO

fornodes, atnodes, tonodes, key2nodes, SSH::Batch::ForNodes, Net::OpenSSH.

Back to TOC