
#/bin/sh
# File	: rel_tape_snaps.sh
# By	: Ronald ten Broeke (1st rel), Maarten.deBoer@AtosOrigin.com, 091216
# Subject	:
# release snapmirror relations after snapmirror-to-tape backups
# to be run by cron at regular intervals
# 20070612 Added mailingmechanism (RtB)

PGM="`basename $0|cut -d\. -f1`"
VERSION="0.2"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
FILERS="nlnaf13 nlnaf14 nlnaf15 nlnaf16"
SSH="/usr/bin/ssh -n"

touch ${LOG}
EC=$?
if [ ${EC} -gt 0 ]; then
  echo "Problems with writing (${EC}) to ${LOG}. Exiting ..."
  exit 1
fi

# Get a list of tape-snapshots. With date not today. And remove the (old)(tape-)snapshots
DATE="`date +%d_%m_%y`"
for FILER in ${FILERS}
do
  ${SSH} ${FILER} snapmirror status|grep tape|grep Idle|grep -v "${DATE}"|awk '{print $1, $2}' | while read SOURCE DEST
  do
    SRCVOL="`echo ${SOURCE} | cut -d\: -f2`"
    echo "`date +%Y-%m-%d_%H:%M:%S` ${PGM}:Will release at ${FILER} vol. ${SRCVOL} to ${DEST}" | tee -a ${LOG}
    ${SSH} ${FILER} snapmirror release ${SRCVOL} ${DEST}
  done
done

exit
#--------------

DESTS=`ssh hwnaf01 snapmirror status | grep tape | grep Idle | awk '{print $1, $2}'`
>/tmp/sm_snaptape_release.sh
test -n "$DESTS" && echo "`date`:\n$DESTS" >> /tmp/t5

test -n "$DESTS" && echo "$DESTS" | while read SOURCE DEST
      do 
         SOURCE1=`echo $SOURCE | cut -d: -f2`
         echo "ssh hwnaf01 snapmirror release $SOURCE1 $DEST" >>/tmp/sm_snaptape_release.sh
      done
sh /tmp/sm_snaptape_release.sh

FAIL=`grep "No release-able destination found" $LOGF`
if test -n "${FAIL}"
then
cat $LOGF | mailx -s ":hwnaf01: output release_snap_tape.sh" gmnl-msscentral@atosorigin.com
fi

