[cluster] Don't force root login any more

The login was hard-coded to root, this was fixed to use by default the
local login name. The option -l was added to allow to specify a
different login name.
This commit is contained in:
Matteo Cypriani 2013-05-01 16:12:09 -04:00
parent 9d5b36f5bd
commit 97b1630fc8
4 changed files with 149 additions and 15 deletions

View File

@ -1,7 +1,8 @@
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:
fping. They all take as first and mandatory positional argument a host
list name “NAME”; the list will be searched according to the following
pattern:
``` $HOME/.config/cluster/NAME.lst
@ -20,7 +21,13 @@ for example:
priam
```
The scripts provided are detailed in the sequel.
The scrits based on SSH use the local user's login name as remote login;
this can be changed using the ``-l`` option, that must appear before the
hosts' list on the command line, for example:
``` cluster-run -l root openwrt_machines opkg install screen
The provided scripts are detailed in the sequel.
= cluster-ping.sh =

View File

@ -10,22 +10,63 @@
#
# Deploy files on a number of remote hosts using Parallel SCP.
if [ $# -lt 2 ] ; then
echo "Usage: $0 <hosts_list> <file1> [file2 [...]]"
print_usage()
{
echo "Usage: $0 [-l login] <hosts_list> <file1> [file2 [...]]"
}
# Parse the optional arguments with getopt
export POSIXLY_CORRECT=yes
export GETOPT_COMPATIBLE=yes
OPTSTRING="l:"
ARGS=$(getopt $OPTSTRING $*)
if [ $? -ne 0 ] ; then
print_usage
exit 1
fi
set -- $ARGS
while [ $# -ne 0 ] ; do
case "$1" in
-l)
LOGIN="$2"
shift
shift
;;
--)
shift
break
;;
*)
echo "Unknown argument:" $1
exit 2
esac
done
# Do we have at least a host list and a command?
if [ $# -lt 2 ] ; then
print_usage
exit 3
fi
# Check dependencies
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
exit 4
fi
# Hosts' list file
HOSTS="$HOME/.config/cluster/$1.lst"
shift
echo "Using file '$HOSTS' as hosts' list."
# Login
if [ "$LOGIN" != "" ] ; then
echo "Login: $LOGIN"
LOGIN="-l $LOGIN"
fi
for FILE in $@ ; do
echo "Deploying '$FILE'..."
$PSCP -r -l root -h "$HOSTS" -- "$FILE" /root
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" /root
done

View File

@ -10,20 +10,64 @@
#
# Run a command on a list of remote hosts using Parallel SSH.
if [ $# -lt 2 ] ; then
echo "Usage: $0 <hosts_list> <command>"
#set -x
print_usage()
{
echo "Usage: $0 [-l login] <hosts_list> <command>"
}
# Parse the optional arguments with getopt
export POSIXLY_CORRECT=yes
export GETOPT_COMPATIBLE=yes
OPTSTRING="l:"
ARGS=$(getopt $OPTSTRING $*)
if [ $? -ne 0 ] ; then
print_usage
exit 1
fi
set -- $ARGS
while [ $# -ne 0 ] ; do
case "$1" in
-l)
LOGIN="$2"
shift
shift
;;
--)
shift
break
;;
*)
echo "Unknown argument:" $1
exit 2
esac
done
# Do we have at least a host list and a command?
if [ $# -lt 2 ] ; then
print_usage
exit 3
fi
# Check dependencies
PSSH=$(command -v parallel-ssh || command -v pssh)
if [ "$PSSH" = "" ] ; then
echo "Parallel SSH (pssh) is required for this script to work."
exit 2
exit 4
fi
# Hosts' list file
HOSTS="$HOME/.config/cluster/$1.lst"
shift
echo "Using file '$HOSTS' as hosts' list."
echo "Command: $@"
exec $PSSH --print -l root -h "$HOSTS" -- $@
# Login
if [ "$LOGIN" != "" ] ; then
echo "Login: $LOGIN"
LOGIN="-l $LOGIN"
fi
echo "Command:" "$@"
exec $PSSH --print $LOGIN -h "$HOSTS" -- "$@"

View File

@ -11,15 +11,57 @@
# 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>"
print_usage()
{
echo "Usage: $0 [-l login] <hosts_list>"
}
# Parse the optional arguments with getopt
export POSIXLY_CORRECT=yes
export GETOPT_COMPATIBLE=yes
OPTSTRING="l:"
ARGS=$(getopt $OPTSTRING $*)
if [ $? -ne 0 ] ; then
print_usage
exit 1
fi
set -- $ARGS
while [ $# -ne 0 ] ; do
case "$1" in
-l)
LOGIN="$2"
shift
shift
;;
--)
shift
break
;;
*)
echo "Unknown argument:" $1
exit 2
esac
done
# Do we have only one argument left?
if [ $# -ne 1 ] ; then
print_usage
exit 3
fi
# Hosts' list file
HOSTS="$HOME/.config/cluster/$1.lst"
shift
echo "Using file '$HOSTS' as hosts' list."
# Login
if [ "$LOGIN" != "" ] ; then
echo "Login: $LOGIN"
LOGIN="${LOGIN}@"
fi
# Create the screen tabs
for HOST in $(cat "$HOSTS") ; do
screen -t $HOST ssh root@$HOST
SSH="ssh ${LOGIN}${HOST}"
screen -t "$SSH" $SSH
done