#!/bin/bash
#
# multiscp.sh - A small script to scp files to several hosts.
# Copyright (C) 2002 Oskar Andreasson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
# USA
#
# $Id: multissh.sh,v 1.2 2003/09/09 14:10:05 blueflux Exp $

#
# config
#
sto_as="sto-1 sto2 sto-3"

usala_as="usala-1 usala-2"

all_as="$sto_as $usala_as"

all_db="db-1 db-2"

all_other="dns mail www"

test_as="testmachine"


function ssh-all-db () {
        user=$1
	shift 2
	command=$*
	for host in $all_db ; do
		echo "$host:"
		ssh -l $user $host $command
	done
}

function ssh-all-as () {
	user=$1
	shift 2
	command=$*
	for host in $all_as ; do
		echo "$host:"
		ssh -l $user $host $command
	done
}

function ssh-sto-as () {
	user=$1
	shift 2
	command=$*
	for host in $sto_as ; do
		echo "$host:"
		ssh -l $user $host $command
	done
}

function ssh-test-as () {
	user=$1
	shift 2
	command=$*
	for host in $test_as ; do
		echo "$host:"
		ssh -l $user $host $command
	done
}

function ssh-usala-as () {
	user=$1
	shift 2
	command=$*
	for host in $usala_as ; do
		echo "$host:"
		ssh -l $user $host $command
	done
}

function usage () {
cat << EOF
SSH groups of hosts executing specific commands on all.

$0 <user> <sshgroup> <command>

SSHgroups: ssh-all-as, ssh-sto-as, ssh-usala-as, all-db, all-other
EOF
}

case $2 in
	all-as)
	ssh-all-as $*
	;;
	sto-as)
	ssh-sto-as $*
	;;
	usala-as)
	ssh-usala-as $*
	;;
	test-as)
	ssh-test-as $*
	;;
	all-db)
	ssh-all-db $*
	;;
	*)
	usage
	;;
esac
