Professional Documents
Culture Documents
/bin/ksh
# set -x
. /nsr/scripts/.profile
. /root/.profile
########################
### Avoid Manual Run ###
########################
CURRENT_TIME_EPOCH=`date +%s`
CURRENTHOUR=`date +"%H"`
CURRENTMINUTE=`date +"%M"`
if [ $1 ] && [ $1 = NO_MANUAL_RUN ] && [ $CURRENTHOUR = 08 ] && [ $CURRENTMINUTE =
00 ]
then
echo "Proceeding..." >/dev/null
else
echo "Exiting...Running this script manually is prohibited"
exit
fi
############################
### Avoid Multiple Users ###
############################
BASE=/nsr/scripts/group_configuration_checks
ls $BASE/.lock* >> /dev/null 2>&1
if [ $? = 0 ]
then
echo "Cannot proceed; There is a lock"
echo "exiting..."
exit
else
touch $BASE/.lock.$SUDO_USER
chmod 600 $BASE/.lock.$SUDO_USER
fi
trap "rm $BASE/.lock.$SUDO_USER;echo interrupted...;exit" 2
#########################################
### Define DAY_OF_MONTH and Schedule ###
#########################################
touch $BASE/schedules
TODAY=`date +"%a"`
DAYNUMBER=`date +"%d"`
MONTHNUMBER=`date +"%m"`
DAY_OF_MONTH=all
###
if [ $TODAY = "Fri" ] && [ $DAYNUMBER -le 07 ] && [ $MONTHNUMBER -le 01 ]
then
DAY_OF_MONTH=ffj
echo "Today is First Friday of January. Validating daily run of FS groups and
yearly run of non-FS groups"
echo
"----------------------------------------------------------------------------------
-----------------"
grep "_D " $BASE/schedules_orig_do_not_remove | grep FS_ >> $BASE/schedules
grep "_Y " $BASE/schedules_orig_do_not_remove | grep -v FS_ >>
$BASE/schedules
fi
if [ $TODAY = "Sat" ] && [ $DAYNUMBER -ge 02 ] && [ $DAYNUMBER -le 08 ] &&
[ $MONTHNUMBER -le 01 ]
then
DAY_OF_MONTH=sffj
echo "Today is Saturday after First Friday of January. Validating Yearly run
of FS groups and daily run of non-FS groups"
echo
"----------------------------------------------------------------------------------
--------------------------------"
grep "_Y " $BASE/schedules_orig_do_not_remove | grep FS_ >> $BASE/schedules
grep "_D " $BASE/schedules_orig_do_not_remove | grep -v FS_ | grep -v NM_ >>
$BASE/schedules
fi
###
if [ $TODAY = "Fri" ] && [ $DAYNUMBER -le 07 ] && [ $MONTHNUMBER -ge 02 ]
then
DAY_OF_MONTH=ffr
echo "Today is First Friday of Feb-Dec. Validating daily run of FS groups and
Monthly run of non-FS groups"
echo
"----------------------------------------------------------------------------------
------------------"
grep "_D " $BASE/schedules_orig_do_not_remove | grep FS_ >> $BASE/schedules
grep "_M " $BASE/schedules_orig_do_not_remove | grep -v FS_ >>
$BASE/schedules
fi
if [ $TODAY = "Sat" ] && [ $DAYNUMBER -ge 02 ] && [ $DAYNUMBER -le 08 ] &&
[ $MONTHNUMBER -ge 02 ]
then
DAY_OF_MONTH=sffr
echo "Today is Saturday after First Friday of Feb-Dec. Validating Monthly run
of FS groups and daily run of non-FS groups"
echo
"----------------------------------------------------------------------------------
---------------------------------"
grep "_M " $BASE/schedules_orig_do_not_remove | grep FS_ >> $BASE/schedules
grep "_D " $BASE/schedules_orig_do_not_remove | grep -v FS_ | grep -v NM_ >>
$BASE/schedules
fi
###
if [ $DAY_OF_MONTH = all ]
then
echo "Today is a regular day. Validating daily run of all groups"
echo "----------------------------------------------------------"
grep "_D " $BASE/schedules_orig_do_not_remove | grep -v NM_ >>
$BASE/schedules
fi
##################################
### Check for group run status ###
##################################
LAST_START=`date -d @$LAST_START_EPOCH`
((TIME_SINCE_LAST_START=$CURRENT_TIME_EPOCH-$LAST_START_EPOCH))
ACTUAL_START_TIME=`echo $LAST_START | awk '{print $4}' | cut -d ":" -f1-2`
if [ $ACTUAL_START_TIME ] && [ $ACTUAL_START_TIME = $SCHEDULED_START_TIME ]
then
SCHEDULED_START=true
else
SCHEDULED_START=false
fi
if [ $TIME_SINCE_LAST_START -lt 86405 ] && [ $SCHEDULED_START = true ]
then
# echo -e "$GROUP started within last one day AND started at its scheduled
time, at $ACTUAL_START_TIME"
echo "$GROUP started within last one day AND started at its scheduled time,
at $ACTUAL_START_TIME"
else
if [ $TIME_SINCE_LAST_START -lt 86405 ] && [ $SCHEDULED_START = false ]
then
# echo -e "$GROUP started within last one day BUT started at
$ACTUAL_START_TIME instead of scheduled start at $SCHEDULED_START_TIME ----> Please
investigate"
echo "$GROUP started within last one day BUT started at
$ACTUAL_START_TIME instead of scheduled start at $SCHEDULED_START_TIME ----> Please
investigate"
echo "$GROUP started within last one day BUT started at
$ACTUAL_START_TIME instead of scheduled start at $SCHEDULED_START_TIME" >>
$BASE/errors
else
echo -e "show name \n print type:NSR client;group:$GROUP;scheduled
backup:enabled" | nsradmin -s mv3wbksv01prv-prod.smrc.sidra.org -i - >> /dev/null
2>&1
if [ $? = 0 ]
then
# echo -e "$GROUP did not start within last one day
----------------------------> Please investigate"
echo "$GROUP did not start within last one day
----------------------------> Please investigate"
echo "$GROUP did not start within last one day" >> $BASE/errors
else
# echo -e "$GROUP did not start within last one day but no
worries, there are no (enabled) clients assigned to it"
echo "$GROUP did not start within last one day but no worries,
there are no (enabled) clients assigned to it"
fi
fi
fi
((i++))
done
##############################
### Send Alert and Cleanup ###
##############################
ls $BASE/errors >> /dev/null 2>&1
if [ $? = 0 ]
then
echo -e "`date +%D` Investigate following group run errors and fix the issues
before 4pm today \n \n`cat $BASE/errors` " | /bin/mailx -s
"mv3wbksv01prv.smrc.sidra.org's ATWE notification,Hostname: mv3wbksv01prv, Profile:
Custom, Severity: 3"
mwahajuddin@sidra.org,mhouhou@sidra.org,sawad@sidra.org,ptummala.dell@sidra.org,dl-
sidra-backup@dell.com,atwe_sid_networker@dell.com -- -f networker@sidra.org
mv $BASE/errors $BASE/errors_lastrun
fi
mv $BASE/schedules $BASE/schedules_lastrun
rm $BASE/.lock.$SUDO_USER