|
Packit |
857059 |
#!/bin/bash
|
|
Packit |
857059 |
# BEGIN_ICS_COPYRIGHT8 ****************************************
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# Copyright (c) 2015, Intel Corporation
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# Redistribution and use in source and binary forms, with or without
|
|
Packit |
857059 |
# modification, are permitted provided that the following conditions are met:
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
857059 |
# this list of conditions and the following disclaimer.
|
|
Packit |
857059 |
# * Redistributions in binary form must reproduce the above copyright
|
|
Packit |
857059 |
# notice, this list of conditions and the following disclaimer in the
|
|
Packit |
857059 |
# documentation and/or other materials provided with the distribution.
|
|
Packit |
857059 |
# * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
857059 |
# may be used to endorse or promote products derived from this software
|
|
Packit |
857059 |
# without specific prior written permission.
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
857059 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
857059 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
Packit |
857059 |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
Packit |
857059 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Packit |
857059 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
Packit |
857059 |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
Packit |
857059 |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Packit |
857059 |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Packit |
857059 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
857059 |
#
|
|
Packit |
857059 |
# END_ICS_COPYRIGHT8 ****************************************
|
|
Packit |
857059 |
|
|
Packit |
857059 |
# [ICS VERSION STRING: unknown]
|
|
Packit |
857059 |
# copy a file to all hosts
|
|
Packit |
857059 |
|
|
Packit |
857059 |
# optional override of defaults
|
|
Packit |
857059 |
if [ -f /etc/opa/opafastfabric.conf ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
. /etc/opa/opafastfabric.conf
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
|
|
Packit |
857059 |
. /usr/lib/opa/tools/opafastfabric.conf.def
|
|
Packit |
857059 |
|
|
Packit |
857059 |
. /usr/lib/opa/tools/ff_funcs
|
|
Packit |
857059 |
|
|
Packit |
857059 |
temp="$(mktemp --tmpdir "opascpall.XXXXXX")"
|
|
Packit |
857059 |
trap "rm -f $temp; exit 1" SIGHUP SIGTERM SIGINT
|
|
Packit |
857059 |
trap "rm -f $temp" EXIT
|
|
Packit |
857059 |
|
|
Packit |
857059 |
Usage_full()
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
echo "Usage: opascpall [-p] [-r] [-f hostfile] [-h 'hosts'] [-u user]" >&2
|
|
Packit |
857059 |
echo " source_file ... dest_file" >&2
|
|
Packit |
857059 |
echo " opascpall -t [-p] [-f hostfile] [-h 'hosts'] [-u user] " >&2
|
|
Packit |
857059 |
echo " [source_dir [dest_dir]]" >&2
|
|
Packit |
857059 |
echo " or" >&2
|
|
Packit |
857059 |
echo " opascpall --help" >&2
|
|
Packit |
857059 |
echo " --help - produce full help text" >&2
|
|
Packit |
857059 |
echo " -p - perform copy in parallel on all hosts" >&2
|
|
Packit |
857059 |
echo " -r - recursive copy of directories" >&2
|
|
Packit |
857059 |
echo " -t - optimized recursive copy of directories using tar" >&2
|
|
Packit |
857059 |
echo " if dest_dir omitted, defaults to current directory name" >&2
|
|
Packit |
857059 |
echo " if source_dir and dest_dir omitted, both default to current directory" >&2
|
|
Packit |
857059 |
echo " -h hosts - list of hosts to copy to" >&2
|
|
Packit |
857059 |
echo " -f hostfile - file with hosts in cluster, default is $CONFIG_DIR/opa/hosts" >&2
|
|
Packit |
857059 |
echo " -u user - user to perform copy to, default is current user code" >&2
|
|
Packit |
857059 |
echo " source_file - list of source files to copy" >&2
|
|
Packit |
857059 |
echo " source_dir - source directory to copy, if omitted . is used" >&2
|
|
Packit |
857059 |
echo " dest_file - destination for copy." >&2
|
|
Packit |
857059 |
echo " If more than 1 source file, this must be a directory" >&2
|
|
Packit |
857059 |
echo " dest_dir - destination for copy. If omitted current directory name is used" >&2
|
|
Packit |
857059 |
echo " Environment:" >&2
|
|
Packit |
857059 |
echo " HOSTS - list of hosts, used if -h option not supplied" >&2
|
|
Packit |
857059 |
echo " HOSTS_FILE - file containing list of hosts, used in absence of -f and -h" >&2
|
|
Packit |
857059 |
echo " FF_MAX_PARALLEL - when -p option is used, maximum concurrent operations" >&2
|
|
Packit |
857059 |
echo "example:">&2
|
|
Packit |
857059 |
echo " opascpall MPI-PMB /root/MPI-PMB" >&2
|
|
Packit |
857059 |
echo " opascpall -t -p /usr/src/opa/mpi_apps /usr/src/opa/mpi_apps" >&2
|
|
Packit |
857059 |
echo " opascpall a b c /root/tools/" >&2
|
|
Packit |
857059 |
echo " opascpall -h 'arwen elrond' a b c /root/tools" >&2
|
|
Packit |
857059 |
echo " HOSTS='arwen elrond' opascpall a b c /root/tools" >&2
|
|
Packit |
857059 |
echo "user@ syntax cannot be used in filenames specified" >&2
|
|
Packit |
857059 |
echo "To copy from hosts in the cluster to this host, use opauploadall" >&2
|
|
Packit |
857059 |
exit 0
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
Usage()
|
|
Packit |
857059 |
{
|
|
Packit |
857059 |
echo "Usage: opascpall [-p] [-r] [-f hostfile] source_file ... dest_file" >&2
|
|
Packit |
857059 |
echo " opascpall -t [-p] [-f hostfile] [source_dir [dest_dir]]" >&2
|
|
Packit |
857059 |
echo " or" >&2
|
|
Packit |
857059 |
echo " opascpall --help" >&2
|
|
Packit |
857059 |
echo " --help - produce full help text" >&2
|
|
Packit |
857059 |
echo " -p - perform copy in parallel on all hosts" >&2
|
|
Packit |
857059 |
echo " -r - recursive copy of directories" >&2
|
|
Packit |
857059 |
echo " -t - optimized recursive copy of directories using tar" >&2
|
|
Packit |
857059 |
echo " if dest_dir omitted, defaults to current directory name" >&2
|
|
Packit |
857059 |
echo " if source_dir and dest_dir omitted, both default to current directory" >&2
|
|
Packit |
857059 |
echo " -f hostfile - file with hosts in cluster, default is $CONFIG_DIR/opa/hosts" >&2
|
|
Packit |
857059 |
echo " source_file - list of source files to copy" >&2
|
|
Packit |
857059 |
echo " source_dir - source directory to copy, if omitted . is used" >&2
|
|
Packit |
857059 |
echo " dest_file - destination for copy." >&2
|
|
Packit |
857059 |
echo " If more than 1 source file, this must be a directory" >&2
|
|
Packit |
857059 |
echo " dest_dir - destination for copy. If omitted current directory name is used" >&2
|
|
Packit |
857059 |
echo "example:">&2
|
|
Packit |
857059 |
echo " opascpall MPI-PMB /root/MPI-PMB" >&2
|
|
Packit |
857059 |
echo " opascpall -t -p /usr/src/opa/mpi_apps /usr/src/opa/mpi_apps" >&2
|
|
Packit |
857059 |
echo " opascpall a b c /root/tools/" >&2
|
|
Packit |
857059 |
echo "user@ syntax cannot be used in filenames specified" >&2
|
|
Packit |
857059 |
echo "To copy from hosts in the cluster to this host, use opauploadall" >&2
|
|
Packit |
857059 |
exit 2
|
|
Packit |
857059 |
}
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if [ x"$1" = "x--help" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
Usage_full
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
|
|
Packit |
857059 |
user=`id -u -n`
|
|
Packit |
857059 |
opts=
|
|
Packit |
857059 |
topt=n
|
|
Packit |
857059 |
popt=n
|
|
Packit |
857059 |
status=0
|
|
Packit |
857059 |
|
|
Packit |
857059 |
pids=''
|
|
Packit |
857059 |
|
|
Packit |
857059 |
while getopts f:h:u:prt param
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
case $param in
|
|
Packit |
857059 |
h)
|
|
Packit |
857059 |
HOSTS="$OPTARG";;
|
|
Packit |
857059 |
f)
|
|
Packit |
857059 |
HOSTS_FILE="$OPTARG";;
|
|
Packit |
857059 |
u)
|
|
Packit |
857059 |
user="$OPTARG";;
|
|
Packit |
857059 |
p)
|
|
Packit |
857059 |
opts="$opts -q"
|
|
Packit |
857059 |
popt=y;;
|
|
Packit |
857059 |
r)
|
|
Packit |
857059 |
opts="$opts -r";;
|
|
Packit |
857059 |
t)
|
|
Packit |
857059 |
topt=y;;
|
|
Packit |
857059 |
?)
|
|
Packit |
857059 |
Usage;;
|
|
Packit |
857059 |
esac
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
shift $((OPTIND -1))
|
|
Packit |
857059 |
if [ "$topt" = "n" -a $# -lt 2 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
Usage
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
if [ "$topt" = "y" -a $# -gt 2 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
Usage
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
check_host_args opascpall
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if [ "$topt" = "n" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
# remove last name from the list
|
|
Packit |
857059 |
files=
|
|
Packit |
857059 |
dest=
|
|
Packit |
857059 |
for file in "$@"
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
if [ ! -z "$dest" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
files="$files $dest"
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
dest="$file"
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
|
|
Packit |
857059 |
running=0
|
|
Packit |
857059 |
|
|
Packit |
857059 |
for hostname in $HOSTS
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
if [ "$popt" = "y" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
if [ $running -ge $FF_MAX_PARALLEL ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
wait
|
|
Packit |
857059 |
running=0
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
echo "scp $opts $files $user@[$hostname]:$dest"
|
|
Packit |
857059 |
scp $opts $files $user@\[$hostname\]:$dest &
|
|
Packit |
857059 |
pid=$!
|
|
Packit |
857059 |
pids="$pids $pid"
|
|
Packit |
857059 |
running=$(( $running + 1))
|
|
Packit |
857059 |
else
|
|
Packit |
857059 |
echo "scp $opts $files $user@[$hostname]:$dest"
|
|
Packit |
857059 |
scp $opts $files $user@\[$hostname\]:$dest
|
|
Packit |
857059 |
if [ "$?" -ne 0 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
status=1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
|
|
Packit |
857059 |
#checking exit status for background jobs
|
|
Packit |
857059 |
for pid in $pids
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
wait $pid
|
|
Packit |
857059 |
if [ "$?" -ne 0 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
status=1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
|
|
Packit |
857059 |
else
|
|
Packit |
857059 |
if [ $# -lt 2 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
destdir=$PWD
|
|
Packit |
857059 |
else
|
|
Packit |
857059 |
destdir=$2
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
if [ $# -lt 1 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
srcdir=$PWD
|
|
Packit |
857059 |
else
|
|
Packit |
857059 |
srcdir=$1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
if [ ! -d $srcdir ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
echo "opascpall: $srcdir: No such directory" >&2
|
|
Packit |
857059 |
Usage
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
cd $srcdir
|
|
Packit |
857059 |
tar cvfz $temp .
|
|
Packit |
857059 |
|
|
Packit |
857059 |
running=0
|
|
Packit |
857059 |
for hostname in $HOSTS
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
if [ "$popt" = "y" ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
if [ $running -ge $FF_MAX_PARALLEL ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
wait
|
|
Packit |
857059 |
running=0
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
(
|
|
Packit |
857059 |
echo "scp $opts $temp $user@[$hostname]:$temp"
|
|
Packit |
857059 |
scp $opts $temp $user@\[$hostname\]:$temp
|
|
Packit |
857059 |
echo "$user@$hostname: mkdir -p $destdir; cd $destdir; tar xfz $temp; rm -f $temp"
|
|
Packit |
857059 |
ssh $user@$hostname "mkdir -p $destdir; cd $destdir; tar xfz $temp; rm -f $temp"
|
|
Packit |
857059 |
) &
|
|
Packit |
857059 |
pid=$!
|
|
Packit |
857059 |
pids="$pids $pid"
|
|
Packit |
857059 |
running=$(( $running + 1))
|
|
Packit |
857059 |
else
|
|
Packit |
857059 |
echo "scp $opts $temp $user@[$hostname]:$temp"
|
|
Packit |
857059 |
scp $opts $temp $user@\[$hostname\]:$temp
|
|
Packit |
857059 |
if [ "$?" -ne 0 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
status=1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
echo "$user@$hostname: mkdir -p $destdir; cd $destdir; tar xfz $temp; rm -f $temp"
|
|
Packit |
857059 |
ssh $user@$hostname "mkdir -p $destdir; cd $destdir; tar xfz $temp; rm -f $temp"
|
|
Packit |
857059 |
if [ "$?" -ne 0 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
status=1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
|
|
Packit |
857059 |
#checking exit status for background jobs
|
|
Packit |
857059 |
for pid in $pids
|
|
Packit |
857059 |
do
|
|
Packit |
857059 |
wait $pid
|
|
Packit |
857059 |
if [ "$?" -ne 0 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
status=1
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
done
|
|
Packit |
857059 |
rm -f $temp
|
|
Packit |
857059 |
fi
|
|
Packit |
857059 |
|
|
Packit |
857059 |
if [ $status -ne 0 ]
|
|
Packit |
857059 |
then
|
|
Packit |
857059 |
exit 1
|
|
Packit |
857059 |
fi
|