#!/bin/ksh ######################################################################### # # # Script to generate Policy Configuration report # # Modification Date: 07/23/2010 # # Written By: Don Wilder # # This script generates a status report for NBU policies # # and mails the reports to someone_who_cares # # # ######################################################################### Version='1.01' appName=${0##*/} someone_who_cares=" [email distribition list] " # Customize this to where you want to keep the history files HISTORY_DIR=/usr/openv/nbu_history/Policy_History ARCHIVE_DIR=${HISTORY_DIR}/change_logs OUTPUT=${HISTORY_DIR}/nbu_policies.current OUTPUT1=${HISTORY_DIR}/nbu_policies.previous REPORT=${HISTORY_DIR}/nbu_policy-rpt REPORT1=${HISTORY_DIR}/nbu_policy-rpt.tmp POLICY=/tmp/nbu_policy-detail-rpt A_DATE=`date +%Y-%b-%d` #echo "History Dir = ${HISTORY_DIR}" #echo "Archive Dir = ${ARCHIVE_DIR}" #echo "Output File Current = ${OUTPUT}" #echo "Output File Previous = ${OUTPUT1}" #echo "Report File = ${REPORT}" #echo "Report File temp = ${REPORT1}" #echo "Policy Detail temp File = ${POLICY}" #echo "Date to be appended to logfile = ${A_DATE}" today=`date +%w` yesterday=$(( ${today} - 1 )) if [ ${yesterday} = -1 ] then yesterday=6 fi ADMCMD=/usr/openv/netbackup/bin/admincmd FORM1=" Changed Policies on `/usr/bin/hostname`" FORM2=" *************************************************" FORM3=" " FORM4="===============================================================================" FORM5=" Detailed Report" FORM6="_______________________________________________________________________________" ##################################################################################### # Begin Main Script ##################################################################################### # # Move previous run's output to a hold file. if [ -s ${OUTPUT} ] then mv ${OUTPUT} ${OUTPUT1} fi # Initalize the current policy echo "${FORM3}" > ${POLICY} for i in `${ADMCMD}/bppllist -l` do echo "Policy Name: ${i}" > ${HISTORY_DIR}/${i}.${today} echo "${FORM6}" >> ${HISTORY_DIR}/${i}.${today} ${ADMCMD}/bpplclients ${i} >> ${HISTORY_DIR}/${i}.${today} echo "${FORM6}" >> ${HISTORY_DIR}/${i}.${today} ${ADMCMD}/bpplinfo ${i} -L >> ${HISTORY_DIR}/${i}.${today} echo "${FORM6}" >> ${HISTORY_DIR}/${i}.${today} ${ADMCMD}/bpplsched ${i} -L >> ${HISTORY_DIR}/${i}.${today} echo "${FORM4}" >> ${HISTORY_DIR}/${i}.${today} cat ${HISTORY_DIR}/${i}.${today} > ${POLICY} SED_LINE="-e 's/^/${i} - /g'" eval "sed ${SED_LINE} \"${POLICY}\" >> ${OUTPUT}" done # # Compare the current report to the previous run. diff ${OUTPUT} ${OUTPUT1} > ${REPORT1} if [ -s ${REPORT1} ] then # Now we can e-mail it to the right person # Format Report with Title, etc. echo > ${REPORT} echo "${FORM1}" >> ${REPORT} echo "${FORM2}" >> ${REPORT} echo "${FORM3}" >> ${REPORT} echo "${FORM4}" >> ${REPORT} echo >> ${REPORT} cat ${REPORT1} >> ${REPORT} echo "${FORM4}" >> ${REPORT} echo "${FORM5}" >> ${REPORT} echo "${FORM6}" >> ${REPORT} echo >> ${REPORT} for i in `${ADMCMD}/bppllist -l` do echo "${FORM4}" >> ${REPORT} echo "Policy Name: ${i}" >> ${REPORT} echo "${FORM6}" >> ${REPORT} echo "${FORM3}" >> ${REPORT} diff -U 20 ${HISTORY_DIR}/${i}.${today} ${HISTORY_DIR}/${i}.${yesterday} >> ${REPORT} echo "${FORM3}" >> ${REPORT} echo "${FORM6}" >> ${REPORT} done echo >> ${REPORT} echo "${FORM4}" >> ${REPORT} # # Uncomment if you want this to be sent to someone_who_cares today=`date +%m/%d/%y" @ "%H:%M` cat ${REPORT} | mailx -s "NBU Policy Change ALERT ( ${today} )" ${someone_who_cares} cp ${REPORT} ${ARCHIVE_DIR}/nbu_policy_Changed-${A_DATE} rm -f ${REPORT1} # fi # #EOF