diff --git a/bin/cluster-deploy b/bin/cluster-deploy new file mode 120000 index 0000000..ed85a2f --- /dev/null +++ b/bin/cluster-deploy @@ -0,0 +1 @@ +../cluster/cluster-deploy.sh \ No newline at end of file diff --git a/bin/cluster-ping b/bin/cluster-ping new file mode 120000 index 0000000..4f6023f --- /dev/null +++ b/bin/cluster-ping @@ -0,0 +1 @@ +../cluster/cluster-ping.sh \ No newline at end of file diff --git a/bin/cluster-run b/bin/cluster-run new file mode 120000 index 0000000..578c666 --- /dev/null +++ b/bin/cluster-run @@ -0,0 +1 @@ +../cluster/cluster-run.sh \ No newline at end of file diff --git a/bin/cluster-ssh b/bin/cluster-ssh new file mode 120000 index 0000000..d3f0a60 --- /dev/null +++ b/bin/cluster-ssh @@ -0,0 +1 @@ +../cluster/cluster-ssh.sh \ No newline at end of file diff --git a/cluster/README b/cluster/README new file mode 100644 index 0000000..209a075 --- /dev/null +++ b/cluster/README @@ -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) diff --git a/cluster/cluster-deploy.sh b/cluster/cluster-deploy.sh new file mode 100755 index 0000000..7fd1bf6 --- /dev/null +++ b/cluster/cluster-deploy.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# +# cluster-deploy.sh, Copyright © 2013 Matteo Cypriani +# +# 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 [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 diff --git a/cluster/cluster-ping.sh b/cluster/cluster-ping.sh new file mode 100755 index 0000000..e24d0c3 --- /dev/null +++ b/cluster/cluster-ping.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# +# cluster-ping.sh, Copyright © 2013 Matteo Cypriani +# +# 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 " + exit 1 +fi + +HOSTS="$HOME/.config/cluster/$1.lst" +shift +echo "Using file '$HOSTS' as hosts' list." + +exec fping $(cat "$HOSTS") 2>/dev/null diff --git a/cluster/cluster-run.sh b/cluster/cluster-run.sh new file mode 100755 index 0000000..3e967cf --- /dev/null +++ b/cluster/cluster-run.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# +# cluster-run.sh, Copyright © 2013 Matteo Cypriani +# +# 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 " + 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" -- $@ diff --git a/cluster/cluster-ssh.sh b/cluster/cluster-ssh.sh new file mode 100755 index 0000000..5f54a14 --- /dev/null +++ b/cluster/cluster-ssh.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# +# cluster-ssh.sh, Copyright © 2013 Matteo Cypriani +# +# 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 " + 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