[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:
parent
9d5b36f5bd
commit
97b1630fc8
|
@ -1,7 +1,8 @@
|
||||||
The cluster utilities are script allowing to work in parallel with a
|
The cluster utilities are script allowing to work in parallel with a
|
||||||
number of remote hosts, using utilities such as Parallel SSH (pssh) or
|
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
|
fping. They all take as first and mandatory positional argument a host
|
||||||
“NAME”; the list will be searched according to the following pattern:
|
list name “NAME”; the list will be searched according to the following
|
||||||
|
pattern:
|
||||||
|
|
||||||
``` $HOME/.config/cluster/NAME.lst
|
``` $HOME/.config/cluster/NAME.lst
|
||||||
|
|
||||||
|
@ -20,7 +21,13 @@ for example:
|
||||||
priam
|
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 =
|
= cluster-ping.sh =
|
||||||
|
|
|
@ -10,22 +10,63 @@
|
||||||
#
|
#
|
||||||
# Deploy files on a number of remote hosts using Parallel SCP.
|
# Deploy files on a number of remote hosts using Parallel SCP.
|
||||||
|
|
||||||
if [ $# -lt 2 ] ; then
|
print_usage()
|
||||||
echo "Usage: $0 <hosts_list> <file1> [file2 [...]]"
|
{
|
||||||
|
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
|
exit 1
|
||||||
fi
|
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)
|
PSCP=$(command -v parallel-scp || command -v pscp.pssh || command -v pscp)
|
||||||
if [ "$PSCP" = "" ] ; then
|
if [ "$PSCP" = "" ] ; then
|
||||||
echo "Parallel SSH (pssh) is required for this script to work."
|
echo "Parallel SSH (pssh) is required for this script to work."
|
||||||
exit 2
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Hosts' list file
|
||||||
HOSTS="$HOME/.config/cluster/$1.lst"
|
HOSTS="$HOME/.config/cluster/$1.lst"
|
||||||
shift
|
shift
|
||||||
echo "Using file '$HOSTS' as hosts' list."
|
echo "Using file '$HOSTS' as hosts' list."
|
||||||
|
|
||||||
|
# Login
|
||||||
|
if [ "$LOGIN" != "" ] ; then
|
||||||
|
echo "Login: $LOGIN"
|
||||||
|
LOGIN="-l $LOGIN"
|
||||||
|
fi
|
||||||
|
|
||||||
for FILE in $@ ; do
|
for FILE in $@ ; do
|
||||||
echo "Deploying '$FILE'..."
|
echo "Deploying '$FILE'..."
|
||||||
$PSCP -r -l root -h "$HOSTS" -- "$FILE" /root
|
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" /root
|
||||||
done
|
done
|
||||||
|
|
|
@ -10,20 +10,64 @@
|
||||||
#
|
#
|
||||||
# Run a command on a list of remote hosts using Parallel SSH.
|
# Run a command on a list of remote hosts using Parallel SSH.
|
||||||
|
|
||||||
if [ $# -lt 2 ] ; then
|
#set -x
|
||||||
echo "Usage: $0 <hosts_list> <command>"
|
|
||||||
|
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
|
exit 1
|
||||||
fi
|
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)
|
PSSH=$(command -v parallel-ssh || command -v pssh)
|
||||||
if [ "$PSSH" = "" ] ; then
|
if [ "$PSSH" = "" ] ; then
|
||||||
echo "Parallel SSH (pssh) is required for this script to work."
|
echo "Parallel SSH (pssh) is required for this script to work."
|
||||||
exit 2
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Hosts' list file
|
||||||
HOSTS="$HOME/.config/cluster/$1.lst"
|
HOSTS="$HOME/.config/cluster/$1.lst"
|
||||||
shift
|
shift
|
||||||
echo "Using file '$HOSTS' as hosts' list."
|
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" -- "$@"
|
||||||
|
|
|
@ -11,15 +11,57 @@
|
||||||
# Open an SSH interactive shell on a list of remote hosts, opening one
|
# Open an SSH interactive shell on a list of remote hosts, opening one
|
||||||
# GNU Screen tab per host.
|
# GNU Screen tab per host.
|
||||||
|
|
||||||
if [ $# -ne 1 ] ; then
|
print_usage()
|
||||||
echo "Usage: $0 <hosts_list>"
|
{
|
||||||
|
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
|
exit 1
|
||||||
fi
|
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"
|
HOSTS="$HOME/.config/cluster/$1.lst"
|
||||||
shift
|
shift
|
||||||
echo "Using file '$HOSTS' as hosts' list."
|
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
|
for HOST in $(cat "$HOSTS") ; do
|
||||||
screen -t $HOST ssh root@$HOST
|
SSH="ssh ${LOGIN}${HOST}"
|
||||||
|
screen -t "$SSH" $SSH
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue