issue related to shell script
Hi Team,
I have created .sh script to rsync my two folder on web server, now the issue is script runs i can see in cron job but it does not sync the folder as i wanted. below i have just copy and pasted the script example that i have used. one more thing same script is running on another server and it works fine.
it would be gr8 if any one can help me on below.
Thanks
Manglesh
#!/bin/bash
SCRIPT_VERSION=0.04
############
# Variables
############
# Directory to monitor
FLDR="/var/www/webapps/ /var/www/webapps/"
# Delay in second to wait after some modification was made to run the sync process
DELAY_TIME=5
# IP address to keep synchronized
#PROD_IP="10.0.20.20"
PROD_IP="10.0.20.20"
# Log file where the script log the date/time of the last synchronization
LOG_FILE=/var/rspd.log
############
# Functions
############
show_usage() {
echo "$0 - version $SCRIPT_VERSION"
echo ""
echo "This program purposes is to run a synchronization process only if the source is old enough."
echo "It has been designed to be run from crontab and so, it doesn't output anything unless a problem occurs."
echo "All the configuration can be made through the header Variables section of the script."
echo ""
echo "Anyway if you want to know what happen, had the -v (verbose) option"
echo ""
echo ""
echo "Usage: $0 [-v|-h]"
echo ""
echo " -v verbose mode"
echo " -h this help screen"
echo ""
}
############
# Main Prog
############
if [ "$1" == "-h" ]
then
show_usage
exit 0
fi
if [ "$1" == "-v" ]
then
SCRIPT_VERBOSE=1
fi
C_TS=$(date +%s)
if [ ! ${C_TS} ]
then
echo "ERROR: Unable to get current date, you're probably using an old version of date"
exit 1
fi
A_TS=$(ls -lR --time-style=+%s $TDIR | awk '{ print $6}' | sort -un | tail -1)
if [ ! ${C_TS} ]
then
echo "ERROR: Unable to get last modification time, you're probably using an old version of ls"
exit 1
fi
DIFF_TIME=$(expr $C_TS - $A_TS 2> /dev/null)
if [ ! ${DIFF_TIME} ]
then
echo "ERROR: Unable to get time difference"
exit 1
fi
echo "starting rspd.sh" >> $LOG_FILE
if [ ${DIFF_TIME} -gt ${DELAY_TIME} ]
then
[ ${SCRIPT_VERBOSE} ] && echo "Last modification is more than $DIFF_TIME seconds old, running synchronization..."
echo $(date)" - Running synchronization on $PROD_IP" > $LOG_FILE
for IP_ADDR in ${PROD_IP}
do
for DIR in ${FLDR}
do
echo \c $(date)" $IP_ADDR - $DIR - Synchronizing " >> $LOG_FILE
rsync -v -z -ae ssh --exclude-from=/var/xyz/rsync_prod.exclude --delete --delete-after ${DIR}/ ${IP_ADDR}:${DIR}
echo rsync -z -ae ssh --exclude-from=/var/xyz/rsync_prod.exclude --delete --delete-after ${DIR}/ ${IP_ADDR}:${DIR}
if [ $? -ne 0 ]
then
echo $(date)" $IP_ADDR - Synchronization FAILED" >> $LOG_FILE
echo "ERROR: Copy from ${DIR} to ${IP_ADDR} failed, aborting..." >> $LOG_FILE
exit
else
echo " .. OK" >> $LOG_FILE
fi
done
done
else
[ ${SCRIPT_VERBOSE} ] && echo "Last modification is less than $DIFF_TIME seconds old, won't do anything"
exit 0
fi
Last edited by manglesh.vyas; 12-07-2010 at 11:44 AM.
|