My Geeky Page
by Guillaume Chazarain

Polysh

Logo

Polysh is a tool to aggregate several remote shells into one. It is used to launch an interactive remote shell on many machines at once. It is written in Python and requires Python ≥ 2.4.

Here is the transcript of a sample session:

$ polysh 'machine-<01-14>'
waiting (5/14)>

This prompts means we are still waiting for 5 out of 14 remote shells.

ready (14)>

Now this prompts indicates that our 14 remote shells are ready to accept commands.

ready (14)> date
machine-01 : Mon Nov 22 21:26:05 CET 2010
machine-03 : Mon Nov 22 21:26:05 CET 2010
machine-06 : Mon Nov 22 21:26:05 CET 2010
machine-07 : Mon Nov 22 21:26:05 CET 2010
machine-10 : Mon Nov 22 21:26:05 CET 2010
machine-11 : Mon Nov 22 21:26:05 CET 2010
machine-12 : Mon Nov 22 21:26:05 CET 2010
machine-09 : Mon Nov 22 21:26:05 CET 2010
machine-13 : Mon Nov 22 21:26:05 CET 2010
machine-14 : Mon Nov 22 21:26:05 CET 2010
machine-02 : Mon Nov 22 21:26:05 CET 2010
machine-04 : Mon Nov 22 21:26:05 CET 2010
machine-05 : Mon Nov 22 21:26:05 CET 2010
machine-08 : Mon Nov 22 21:26:05 CET 2010
ready (14)>

Perfect time synchronization :-)

ready (14)> sleep 1h

Ctrl-C, Ctrl-D and Ctrl-Z are sent to the remote shells, so if Ctrl-Z is pressed now:

machine-01 : [1]+  Stopped                 sleep 1h
machine-03 : [1]+  Stopped                 sleep 1h
machine-06 : [1]+  Stopped                 sleep 1h
machine-10 : [1]+  Stopped                 sleep 1h
machine-11 : [1]+  Stopped                 sleep 1h
machine-12 : [1]+  Stopped                 sleep 1h
machine-09 : [1]+  Stopped                 sleep 1h
machine-14 : [1]+  Stopped                 sleep 1h
machine-13 : [1]+  Stopped                 sleep 1h
machine-02 : [1]+  Stopped                 sleep 1h
machine-07 : [1]+  Stopped                 sleep 1h
machine-05 : [1]+  Stopped                 sleep 1h
machine-08 : [1]+  Stopped                 sleep 1h
machine-04 : [1]+  Stopped                 sleep 1h
ready (14)> fg
machine-01 : sleep 1h
machine-06 : sleep 1h
machine-07 : sleep 1h
machine-10 : sleep 1h
machine-12 : sleep 1h
machine-13 : sleep 1h
machine-14 : sleep 1h
machine-02 : sleep 1h
machine-03 : sleep 1h
machine-04 : sleep 1h
machine-05 : sleep 1h
machine-08 : sleep 1h
machine-09 : sleep 1h
machine-11 : sleep 1h

Pressing Ctrl-C will kill all these sleep processes.

Control commands start with a : and are not sent to the remote shells but are interpreted by polysh.

ready (14)> :help
:add               Add one or many remote shells.
:chdir             Change the current directory of polysh (not the remote shells).
:disable           Disable sending commands to remote shells.
:enable            Enable sending commands to remote shells.
:export_vars       Export some environment variables on enabled remote shells.
:help              List control commands or show their documentations.
:hide_password     Do not echo the next typed line.
:list              List remote shells and their states.
:purge             Delete disabled remote shells.
:quit              Quit polysh.
:reconnect         Try to reconnect to disconnected remote shells.
:rename            Rename all enabled remote shells with the argument.
:replicate         Copy a path from one remote shell to all others
:reset_prompt      Change the prompt to be recognized by polysh.
:send_ctrl         Send a control character to remote shells.
:set_debug         Enable or disable debugging output for remote shells.
:set_log           Duplicate every console I/O into the given local file.
:show_read_buffer  Print the data read by remote shells.
:upload            Upload the specified local path to enabled remote shells.

For example, we can log what we are doing with the :set_log command:

ready (14)> :set_log /tmp/log
ready (14)> ls /srv
machine-01 : cvs
machine-03 : cvs
machine-06 : cvs
machine-07 : cvs
machine-08 : cvs
machine-10 : cvs
machine-11 : cvs
machine-12 : cvs
machine-13 : cvs
machine-09 : cvs
machine-14 : cvs
machine-02 : cvs
machine-04 : cvs
machine-05 : cvs
ready (14)> !cat /tmp/log
> ls /srv
machine-01 : cvs
machine-03 : cvs
machine-06 : cvs
machine-07 : cvs
machine-08 : cvs
machine-10 : cvs
machine-11 : cvs
machine-12 : cvs
machine-13 : cvs
machine-09 : cvs
machine-14 : cvs
machine-02 : cvs
machine-04 : cvs
machine-05 : cvs
> !cat /tmp/log
ready (14)>

Commands prefixed with a ! are executed by a local shell.

Polysh also has some file transfer abilities.

ready (14)> cd /tmp
ready (14)> :enable machine-01
ready (1)> dd if=/dev/urandom bs=1M count=10 of=10m.random
machine-01 : 10+0 records in
machine-01 : 10+0 records out
machine-01 : 10485760 bytes (10 MB) copied, 1.59032 s, 6.6 MB/s
ready (1)> :enable
ready (14)> :replicate machine-01:10m.random
machine-14 : 0 B transferred at 0 B/s
machine-14 : 1067.00 KiB transferred at 711.12 KiB/s
machine-14 : 2.38 MiB transferred at 1146.85 KiB/s
machine-14 : 4.26 MiB transferred at 1669.38 KiB/s
machine-14 : 6.48 MiB transferred at 2.03 MiB/s
machine-14 : 8.73 MiB transferred at 2.17 MiB/s
machine-14 : Done transferring 10496000 bytes (10.01 MiB)
ready (14)> sha1sum 10m.random
machine-01 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-03 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-11 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-06 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-09 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-10 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-13 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-14 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-02 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-07 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-12 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-04 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-05 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
machine-08 : ac8f44beea9ba20ef0954a72cb7b963263660053  10m.random
ready (14)>

Download

Polysh is licensed under the terms of the GNU GPL version 2 or (at your option) any later version.

You will need Python ≥ 2.4. The latest version is Polysh 0.4, (NEWS) available here: polysh-0.4.tar.bz2 or polysh-0.4.tar.gz.

Freecode project page to stay informed: http://freecode.com/projects/polysh.

Git repository hosted on repo.or.cz. To get a snapshot of polysh with a complete history, use the following command:

git clone git://repo.or.cz/polysh.git

Please contact me for any suggestion, problem, feedback…

Valid XHTML 1.1! Valid CSS! and hopefully compliant with your expectations

S