57 lines
1.2 KiB
Bash
Executable File
57 lines
1.2 KiB
Bash
Executable File
#!/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.
|
|
|
|
print_usage()
|
|
{
|
|
echo "Usage: $0 [-l login] <hosts_list>"
|
|
}
|
|
|
|
# We must have either 3 arguments...
|
|
if [ $# -eq 3 ] ; then
|
|
# Parse the optional arguments
|
|
if [ "$1" = "-l" ] ; then
|
|
LOGIN="$2"
|
|
shift
|
|
shift
|
|
else # Option unknown
|
|
print_usage
|
|
exit 1
|
|
fi
|
|
|
|
# ... or only 1
|
|
elif [ $# -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."
|
|
if [ ! -f "$HOSTS" ] ; then
|
|
echo "The hosts' list file doesn't exist or is not a regular file."
|
|
exit 2
|
|
fi
|
|
|
|
# Login
|
|
if [ "$LOGIN" != "" ] ; then
|
|
echo "Login: $LOGIN"
|
|
LOGIN="${LOGIN}@"
|
|
fi
|
|
|
|
# Create the screen tabs
|
|
for HOST in $(cat "$HOSTS") ; do
|
|
SSH="ssh ${LOGIN}${HOST}"
|
|
screen -t "$SSH" $SSH
|
|
done
|