#!/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. print_usage() { echo "Usage: $0 [-l login] " } # 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 if [ -z "$XDG_CONFIG_HOME" ] ; then XDG_CONFIG_HOME="$HOME/.config" fi HOSTS_FILE="$XDG_CONFIG_HOME/cluster/$1.lst" shift echo "Using file '$HOSTS_FILE' as hosts' list." if [ ! -f "$HOSTS_FILE" ] ; then echo "The hosts' list file doesn't exist or is not a regular file." exit 2 fi # Login if [ -n "$LOGIN" ] ; then echo "Login: $LOGIN" LOGIN="${LOGIN}@" fi # Create the screen tabs while read -r HOST ; do SSH="ssh ${LOGIN}${HOST}" # shellcheck disable=SC2086 screen -t "$SSH" $SSH done <"$HOSTS_FILE"