#!/bin/bash export LOCK_FILE=/home/usace/g0cwpa26/rwcds/dd/external/nwdp/project_hourly/docs/lock # We need to make sure only one instance of this is running at a time # If we can create the lock file, all is well. # If we cannot, check its age with perl's -M operator: # If it's older than a day: # touch it to freshen it up, then proceed as normal # Otherwise, exit. if mkdir $LOCK_FILE then echo Lock obtained. else echo Lock failed. Testing lock age. AGE=`perl -e 'printf "%d", ( -M "$ENV{LOCK_FILE}" )'` if [[ $AGE -gt 0 ]] then echo Lock already $AGE days old. Refreshing. touch $LOCK_FILE else echo Lock only $AGE days old. Exiting. exit fi fi for host in pweb dd_wpc dd_cpc do for dir in www script config webexec do /bin/rsync -zav \ /home/usace/g0cwpa26/rwcds/dd/external/nwdp/project_hourly/$dir/ \ $host:/usr/dd/nwdp/project_hourly/$dir \ --rsync-path=/usr/bin/rsync \ --delete-after done done rmdir $LOCK_FILE echo Lock removed.