9 changed files with 164 additions and 0 deletions
@ -0,0 +1,53 @@
|
||||
The cluster utilities are script allowing to work in parallel with a |
||||
number of remote hosts, using utilities such as Parallel SSH (pssh) or |
||||
fping. They all take as first and mandatory argument a host list name |
||||
“NAME”; the list will be searched according to the following pattern: |
||||
|
||||
``` $HOME/.config/cluster/NAME.lst |
||||
|
||||
For example, one can call the cluster-ping.sh script typing: |
||||
|
||||
``` cluster-ping my_hosts |
||||
|
||||
to use the hosts' file $HOME/.config/cluster/my_hosts.lst |
||||
|
||||
The format of such a .lst file is one line per host name or IP address, |
||||
for example: |
||||
|
||||
``` |
||||
192.168.42.1 |
||||
192.168.42.3 |
||||
priam |
||||
``` |
||||
|
||||
The scripts provided are detailed in the sequel. |
||||
|
||||
|
||||
= cluster-ping.sh = |
||||
|
||||
Test the connectivity with the hosts of the list by sending them a ICMP |
||||
echo packet. |
||||
|
||||
Dependency: fping |
||||
|
||||
|
||||
= cluster-ssh.sh = |
||||
|
||||
Open a GNU Screen tab with an interactive SSH session for each host of |
||||
the hosts' list. Must be run inside of an existing Screen. |
||||
|
||||
Dependencies: screen, ssh |
||||
|
||||
|
||||
= cluster-run.sh = |
||||
|
||||
Run the same command on every host of the hosts' list. |
||||
|
||||
Dependency: parallel-ssh (pssh) |
||||
|
||||
|
||||
= cluster-deploy.sh = |
||||
|
||||
Deploy one or more files in parallel on every host of the hosts' list. |
||||
|
||||
Dependency: parallel-scp (pscp) |
@ -0,0 +1,31 @@
|
||||
#!/bin/sh |
||||
# |
||||
# cluster-deploy.sh, Copyright © 2013 Matteo Cypriani <mcy@lm7.fr> |
||||
# |
||||
# This program is free software. It comes without any warranty, to |
||||
# the extent permitted by applicable law. You can redistribute it |
||||
# and/or modify it under the terms of the Do What The Fuck You Want |
||||
# To Public License, Version 2, as published by Sam Hocevar. See |
||||
# http://sam.zoy.org/wtfpl/COPYING for more details. |
||||
# |
||||
# Deploy files on a number of remote hosts using Parallel SCP. |
||||
|
||||
if [ $# -lt 2 ] ; then |
||||
echo "Usage: $0 <hosts_list> <file1> [file2 [...]]" |
||||
exit 1 |
||||
fi |
||||
|
||||
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp) |
||||
if [ "$PSCP" = "" ] ; then |
||||
echo "Parallel SSH (pssh) is required for this script to work." |
||||
exit 2 |
||||
fi |
||||
|
||||
HOSTS="$HOME/.config/cluster/$1.lst" |
||||
shift |
||||
echo "Using file '$HOSTS' as hosts' list." |
||||
|
||||
for FILE in $@ ; do |
||||
echo "Deploying '$FILE'..." |
||||
$PSCP -r -l root -h "$HOSTS" -- "$FILE" /root |
||||
done |
@ -0,0 +1,22 @@
|
||||
#!/bin/sh |
||||
# |
||||
# cluster-ping.sh, Copyright © 2013 Matteo Cypriani <mcy@lm7.fr> |
||||
# |
||||
# This program is free software. It comes without any warranty, to |
||||
# the extent permitted by applicable law. You can redistribute it |
||||
# and/or modify it under the terms of the Do What The Fuck You Want |
||||
# To Public License, Version 2, as published by Sam Hocevar. See |
||||
# http://sam.zoy.org/wtfpl/COPYING for more details. |
||||
# |
||||
# Ping a list of remote hosts using fping. |
||||
|
||||
if [ $# -ne 1 ] ; then |
||||
echo "Usage: $0 <hosts_list>" |
||||
exit 1 |
||||
fi |
||||
|
||||
HOSTS="$HOME/.config/cluster/$1.lst" |
||||
shift |
||||
echo "Using file '$HOSTS' as hosts' list." |
||||
|
||||
exec fping $(cat "$HOSTS") 2>/dev/null |
@ -0,0 +1,29 @@
|
||||
#!/bin/sh |
||||
# |
||||
# cluster-run.sh, Copyright © 2013 Matteo Cypriani <mcy@lm7.fr> |
||||
# |
||||
# This program is free software. It comes without any warranty, to |
||||
# the extent permitted by applicable law. You can redistribute it |
||||
# and/or modify it under the terms of the Do What The Fuck You Want |
||||
# To Public License, Version 2, as published by Sam Hocevar. See |
||||
# http://sam.zoy.org/wtfpl/COPYING for more details. |
||||
# |
||||
# Run a command on a list of remote hosts using Parallel SSH. |
||||
|
||||
if [ $# -lt 2 ] ; then |
||||
echo "Usage: $0 <hosts_list> <command>" |
||||
exit 1 |
||||
fi |
||||
|
||||
PSSH=$(command -v parallel-ssh || command -v pssh) |
||||
if [ "$PSSH" = "" ] ; then |
||||
echo "Parallel SSH (pssh) is required for this script to work." |
||||
exit 2 |
||||
fi |
||||
|
||||
HOSTS="$HOME/.config/cluster/$1.lst" |
||||
shift |
||||
echo "Using file '$HOSTS' as hosts' list." |
||||
echo "Command: $@" |
||||
|
||||
exec $PSSH --print -l root -h "$HOSTS" -- $@ |
@ -0,0 +1,25 @@
|
||||
#!/bin/sh |
||||
# |
||||
# cluster-ssh.sh, Copyright © 2013 Matteo Cypriani <mcy@lm7.fr> |
||||
# |
||||
# This program is free software. It comes without any warranty, to |
||||
# the extent permitted by applicable law. You can redistribute it |
||||
# and/or modify it under the terms of the Do What The Fuck You Want |
||||
# To Public License, Version 2, as published by Sam Hocevar. See |
||||
# http://sam.zoy.org/wtfpl/COPYING for more details. |
||||
# |
||||
# Open an SSH interactive shell on a list of remote hosts, opening one |
||||
# GNU Screen tab per host. |
||||
|
||||
if [ $# -ne 1 ] ; then |
||||
echo "Usage: $0 <hosts_list>" |
||||
exit 1 |
||||
fi |
||||
|
||||
HOSTS="$HOME/.config/cluster/$1.lst" |
||||
shift |
||||
echo "Using file '$HOSTS' as hosts' list." |
||||
|
||||
for HOST in $(cat "$HOSTS") ; do |
||||
screen -t $HOST ssh root@$HOST |
||||
done |
Loading…
Reference in new issue