#!/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: multiscp.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-test-as () {
	for host in $test_as ; do
		echo "$host:"
		scp $3 $1@$host:$4
	done
}

function ssh-all-db () {
        for host in $all_db ; do
		echo "$host:"
		scp $3 $1@$host:$4
	done
}

function ssh-all-other () {
        for host in $all_db ; do
		echo "$host:"
		scp $3 $1@$host:$4
	done
}

function ssh-all-as () {
	for host in $all_as ; do
		echo "$host:"
		scp $3 $1@$host:$4
	done
}

function ssh-sto-as () {
	for host in $sto_as ; do
		echo "$host:"
		scp $3 $1@$host:$4
	done
}

function ssh-usala-as () {
	for host in $usala_as ; do
		echo "$host:"
		scp $3 $1@$host:$4
	done
}

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

$0 <user> <sshgroup> <file> <destination>

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

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