LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-07-2010, 12:31 PM   #1
manglesh.vyas
LQ Newbie
 
Registered: Sep 2010
Posts: 5

Rep: Reputation: 0
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 12:44 PM.
 
Old 12-07-2010, 01:57 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
Can you provide more detail on what it is/is not doing, and output from the logfile? What happens when you run the pieces individually from the command line?
 
Old 12-07-2010, 06:39 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,421

Rep: Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815
One thing I can tell you is that your test at the end of $? will always be false, ie equal to zero, because the previous command is echo which would
have to be all sorts of messed up to error.

On your issue, I agree with thesnow that without knowing 'what you wanted' it will be difficult to diagnose the issue.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] a short shell script related to PIDs gujedan Programming 3 11-22-2010 05:54 AM
shell script related to square of number question studywell09 Programming 6 02-07-2010 03:32 PM
Shell script issue suvra82002 Linux - Enterprise 23 07-26-2008 03:02 PM
shell script (bind related) OTIM Programming 6 07-10-2008 05:26 PM
issue with shell script chupacabra Linux - General 3 10-18-2002 09:12 PM


All times are GMT -5. The time now is 08:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration