Hi All!
I am managing databases on handful of servers and standardizing some of the scripts. In order to copy/deploy new version of script I have established passwordless SSH among all the servers and most importantly from my base server.
I developed a simple script that should copy a given file to the list of the servers listed in a list - ASCII Text - file.
Here is the script code:
#!/bin/ksh
set -x
export BKP_SCRIPT=~/scripts/common/bkp_existing.sh
if [ $# -lt 4 ]; then
echo ""
echo "Usage: $0 <SourceDirectory> <SourceFileName> <TargetDirectory> <TargetFileName>"
echo ""
exit 1
fi
export SRC_DIR=$1
export SRC_FILE=$2
export TRGT_DIR=$3
export TRGT_FILE=$4
export TRGT_SRVR_LIST=${SRC_DIR}/deploy_trgt_srvr.list
if [ -s ${TRGT_SRVR_LIST} -a -s ${SRC_DIR}/${SRC_FILE} ]; then
echo "Continue..."
else
echo "Validate source file: ${SRC_DIR}/${SRC_FILE} as well as list file: ${TRGT_SRVR_LIST} exists"
exit 2
fi
cat ${TRGT_SRVR_LIST} | while read RMT_HOST_NAME
do
echo ${RMT_HOST_NAME}
scp -p ${BKP_SCRIPT} ${RMT_HOST_NAME}:${BKP_SCRIPT}
ssh ${RMT_HOST_NAME} ${BKP_SCRIPT} ${TRGT_DIR}/${TRGT_FILE}
scp -p ${SRC_DIR}/${SRC_FILE} ${RMT_HOST_NAME}:${TRGT_DIR}/${TRGT_FILE}
done
If I comment out the scp and ssh command it traverse through all the servers listed in the list file. If not then it process only first line and then stops. I used "set -x" and last line it executes is: "read RMT_HOST_NAME"
Any insights will be most appreciated.