[go: up one dir, main page]

Menu

[r11]: / trunk / km_batch_copy  Maximize  Restore  History

Download this file

71 lines (61 with data), 2.0 kB

#!/bin/bash

################################################################################
# This file is part of key-manager.
#
# key-manager 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 3 of the License, or
# (at your option) any later version.
#
# key-manager 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 key-manager.  If not, see <http://www.gnu.org/licenses/>.
################################################################################

ACCESS=~/access_
let THREAD_COUNT=10

USAGE() {
    echo "$0 <file to copy> [remote destination]"
    echo "<file to copy> must exists."
    echo
    echo "This program copies a given file to each host under key-manager"
    echo "control, and assigned to the group."
    exit 255
}

if [ ${1:-x} == 'x' ]; then
   USAGE
fi

if [ ! -f $1 ]; then
   USAGE
fi

# I guess it's valid to just allow copy to home directory...
#if [ ${2:-x} == 'x' ]; then
#   USAGE
#fi

if [ ${SSH_AGENT_PID:-x} == 'x' ]; then
   echo "you will be much happier if you have launched ssh-agent, and have"
   echo "ssh-add 'ed your id_rsa file."
   read -p 'Do you wish to continue? (y/n) ' RESPONSE
   if [ "$RESPONSE" != 'y' ]; then
      USAGE
   fi
fi

for file in ${ACCESS}*.txt ; do
    temp=${file#$ACCESS}
    user=${temp%.txt}

    let count=0
    cat $file | while read server ; do
        let count=$count+1
        #echo -n "$count "
        scp -q $1 ${user}@${server}:${2} &
        if [ "$count" == "$THREAD_COUNT" ]; then
            #echo waiting
            wait
            let count=0 
        fi
    done
    wait
done