#!/bin/bash ################################################################################ # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # # Uusage: hpcc-push.sh -s -t -n -x # # This is acomplished with a standard scp command with the use of the # runtime users id_rsa file. ###### source ${INSTALL_DIR}/etc/init.d/hpcc_common source ${INSTALL_DIR}/etc/init.d/init-functions source ${INSTALL_DIR}/etc/init.d/export-path usage() { echo "" echo "usage: hpcc-push.sh -s -t -n -x" echo " -n: when specified, denotes the number of concurrent executions threads." echo " The default is 5." echo " -s: source file or directory." echo " -t: target file or directory." echo " -x: when specified, this option excludes execution on the current host." echo "" exit 1 } createScriptFile() { cat > $SCRIPT_FILE < /dev/null 2>&1; then echo "\$IP: Host is alive." CAN_SSH="\`ssh -i $home/$user/.ssh/id_rsa -o BatchMode=yes -o LogLevel=QUIET -o StrictHostKeyChecking=no $user@\$IP exit > /dev/null 2>&1; echo \$?\`" if [ "\$CAN_SSH" -eq 255 ]; then echo "\$IP: Cannot SSH to host."; else echo "\$IP: Copying $source to $target on \$IP"; SCP=\$(scp -r -i $home/$user/.ssh/id_rsa $source $user@\$IP:$target; echo \$?) if [ "\$SCP" -eq 0 ]; then echo "\$IP: Success"; else echo "\$IP: Failure"; exit 1 fi fi else echo "\$IP: Cannot Ping host? (Host Alive?)" exit 1 fi SCRIPTFILE chmod +x ${SCRIPT_FILE} } ############################################ # # MAIN # ############################################ cluster_tools_init if [ "$(whoami)" != "root" ] && [ "$(whoami)" != "${user}" ]; then echo "" echo "The script must run as root, $user or sudo." echo "" exit 1 fi source= target= exclude=0 OPTION="-e ${CONFIG_DIR}/${ENV_CONF_FILE} -s ${SECTION:-DEFAULT}" TEMP=`/usr/bin/getopt -o n:s:t:hx --long help,conrrent:,source:,target:,exclude -n 'hpcc-push' -- "$@"` if [ $? != 0 ] ; then echo "Failure to parse commandline." >&2 ; end 1 ; fi eval set -- "$TEMP" while true ; do case "$1" in -n|--concurrent) if [ -n "$2" ] && [[ $2 =~ ^[0-9]+$ ]] then [ $2 -gt 0 ] && $OPTION="${OPTION:+"$OPTION "}-n $2" fi shift 2 ;; -s|--source) source="$2" shift 2 ;; -t|--target) target="$2" shift 2 ;; -x|--exclude) OPTION="${OPTION:+"$OPTION "}-x" exclude=1 shift ;; -h|--help) usage shift ;; --) shift ; break ;; *) usage ;; esac done if [ -z "$source" ] || [ -z "$target" ]; then usage fi SCRIPT_FILE=~/hpcc-push_$$ createScriptFile python_expected_version=3.4 is_python_installed ${python_expected_version} if [ $? -eq 0 ] then eval ${INSTALL_DIR}/sbin/cluster_script.py -f ${SCRIPT_FILE} $OPTION else echo "" echo "Cannot detect python version ${python_expected_version}+. Will run on the cluster hosts sequentially." echo "" run_cluster ${SCRIPT_FILE} ${exclude} fi rm -rf ${SCRIPT_FILE}