#!/bin/bash # # RUN AS ROOT BASEDIR=/usr/local scriptname="`basename $0`" LOGFILE=${BASEDIR}/logs/${scriptname}.log.`date +%a` LOCKFILE=/var/run/${scriptname}.pid MAIL2=dougie function techo() { echo "`date +%d%b%y_%H:%M:%S` - $*" echo "`date +%d%b%y_%H:%M:%S` - $*" >> ${LOGFILE} } function mtecho() { echo "`date +%d%b%y_%H:%M:%S` - $*" echo "`date +%d%b%y_%H:%M:%S` - $*" >> ${LOGFILE} echo "`date +%d%b%y_%H:%M:%S` - $*" | mail -s "${scriptname} ERROR" $MAIL2 } > $LOGFILE techo "STARTING script: ${scriptname}" # # Look for lock file # techo "Checking for existence of lock file." if [[ -f ${LOCKFILE} ]] ; then techo "Found lockfile: ${LOCKFILE}" pid=`cat ${LOCKFILE}` techo "Checking if process exists for pid: ${pid}" if ps -fp${pid} then techo "Process already running. Exiting." exit else mtecho "No running process found for ${pid}." fi fi pid=$$ techo "Writing pid $pid to lockfile" sudo touch ${LOCKFILE} sudo chmod 777 ${LOCKFILE} echo $pid > ${LOCKFILE} # # Check if tbird2xp is pingable # techo "Checking if tbird2xp is pingable" ping -c 5 -q tbird2xp > /dev/null 2>&1 if [[ $? -eq 0 ]] ; then techo "Can ping tbird2xp." else techo "Cannot ping tbird2xp" rm -f ${LOCKFILE} exit fi # # Check if filesystem already mounted - DRIVE C # if df | grep '/backing_up/tbird2xp/c' then already_mounted=YES techo "Samba drive already mounted" else already_mounted=NO techo "/backing_up/tbird2xp/c not mounted. Attempting to mount." sudo smbmount //tbird2xp/c /backing_up/tbird2xp/c -o guest if df | grep '/backing_up/tbird2xp/c' then techo "/backing_up/tbird2xp/dougie_c mounted succesfully." else mtecho "Although tbird2xp is pingable, there was a problem mounting //tbird2xp/dougie_c" rm -f ${LOCKFILE} exit 2 fi fi rsync -ar --delete --modify-window=2 --exclude '*.CR2' --exclude '*.jbf' --exclude '*.db' --exclude '*.info' --progress /backing_up/tbird2xp/c/photos/ /store/photos #rsync -ar --delete --ignore-existing --progress /backing_up/tbird2xp/c/photos/ /store/photos #rsync -c -ar --modify-window=2 --delete --progress /backing_up/tbird2xp/c/photos/ /store/photos techo "Attempting to unmount /backing_up/tbird2xp/c" sudo umount /backing_up/tbird2xp/c if [[ $? -ne 0 ]] ; then mtecho "There was a problem unmounting /backing_up/tbird2xp/c" else techo "/backing_up/tbird2xp/c unmounted succesfully." fi sudo rm -f ${LOCKFILE}