Rev 7231 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/bin/bash# resolve links - $0 may be a softlinkPRG="$0"while [ -h "$PRG" ]; dols=`ls -ld "$PRG"`link=`expr "$ls" : '.*-> \(.*\)$'`if expr "$link" : '/.*' > /dev/null; thenPRG="$link"elsePRG=`dirname "$PRG"`/"$link"fidoneecho "======================================================="echo "Get the scp/rsync snapshot and mysql table migration snapshot."echo "======================================================="# Get standard environment variablesPRGDIR=`dirname $(readlink -f "$PRG")`hinit() {mv ${PRGDIR}/hashmap.new ${PRGDIR}/hashmap.old}hput() {echo "$1 $2" >> ${PRGDIR}/hashmap.new}hget() {grep "^$2 " ${PRGDIR}/hashmap.$1 | awk '{ print $2 };'}hiterate() {awk '{ print $1 };' ${PRGDIR}/hashmap.$1}cd ${PRGDIR}CATALOG_FILE=`ls -t partial-catalog-*.sql | head -n 1`MYSQL_DUMP="${PRGDIR}/${CATALOG_FILE}"EXPORT_PATH="/var/lib/tomcat6/webapps/export"ALL_RSYNC_DIRS="${EXPORT_PATH}/media ${EXPORT_PATH}/media/website ${EXPORT_PATH}/media/static ${EXPORT_PATH}/documents"ALL_SCP_FILES="${EXPORT_PATH}/javascripts.tgz ${EXPORT_PATH}/html/helpdocs.tgz ${EXPORT_PATH}/html/entities-shop2020.tgz ${EXPORT_PATH}/html/entities-saholic.tgz ${EXPORT_PATH}/partners.tgz ${EXPORT_PATH}/solr.tgz ${MYSQL_DUMP}"PROJECT_DIR="`dirname ${PRGDIR}`"OUT_FILE="${PRGDIR}/catalog_info.txt"OUT_FILE_OLD="${PRGDIR}/catalog_info_old.txt"COMP_FILES=1ALERT=0ALERT_FILE=${PRGDIR}/alert.txt#Empty the alert fileecho > ${ALERT_FILE}#Before getting started move OUT_FILE to OUT_FILE_OLD# also init the hashmap`hinit`if [ -f ${OUT_FILE} ];thencat ${OUT_FILE} > ${OUT_FILE_OLD}elseecho "Could not find the yesterday's validation file. Comapsions cant be performed"COMP_FILES=0fiecho -e "Resource name\tSize\tDir Count\tFile Count" > ${OUT_FILE}for DIR in ${ALL_RSYNC_DIRS}docd ${DIR}FILE_COUNT="$(find ${DIR} -maxdepth 1 -type f | wc -l)"DIR_COUNT="$(find ${DIR} -maxdepth 1 -type d | wc -l)"DIR_SIZE="$(du -k --max-depth 0| awk {'print $1'})"hput "${DIR}|FILE_COUNT" ${FILE_COUNT}hput "${DIR}|DIR_COUNT" ${DIR_COUNT}hput "${DIR}|DIR_SIZE" ${DIR_SIZE}echo -e "${DIR}\t${DIR_SIZE}\t${DIR_COUNT}\t${FILE_COUNT}" >> ${OUT_FILE}donefor FILE in ${ALL_SCP_FILES}doFILE_SIZE=$(ls -la ${FILE} | awk {'print $5'})echo -e "${FILE}\t${FILE_SIZE}" >> ${OUT_FILE}FILE=${FILE/\-[0-9][0-9][0-9][0-9]*/}hput "${FILE}|FILE_SIZE" ${FILE_SIZE}done#get the items count from the mysql serverPAUSED_ITEMS=$(mysql -s --skip-column-names -uroot -pshop2020 catalog -e "select count(*) from item where status = 2")ACTIVE_ITEMS=$(mysql -s --skip-column-names -uroot -pshop2020 catalog -e "select count(*) from item where status = 3")echo "Active items=${ACTIVE_ITEMS}" >> ${OUT_FILE}echo "Paused items=${PAUSED_ITEMS}" >> ${OUT_FILE}hput "ACTIVE_ITEMS_COUNT|NUMBER" ${ACTIVE_ITEMS}hput "PAUSED_ITEMS_COUNT|NUMBER" ${PAUSED_ITEMS}if [ ${COMP_FILES} -ne 0 ]; thenfor KEY in `hiterate old`doNEW_VAL=`hget "new" ${KEY}`OLD_VAL=`hget "old" ${KEY}`if [ ${OLD_VAL} -gt 0 ]; thenDIFF=$(echo "${NEW_VAL} - ${OLD_VAL}"|bc|awk '{ print ($1 >= 0) ? $1 : 0 - $1}')DIFF_PERC=$(echo "scale=2;(${DIFF}*100)/${OLD_VAL}" |bc|awk '{printf "%.2f", $0}')if [ $(echo ${DIFF_PERC} | tr "." " "| awk {'print $1'}) -ge 5 ]; thenALERT=1NAME=$(echo ${KEY} | tr "|" " "| awk {'print $1'})VALUE=$(echo ${KEY} | tr "|" " "| awk {'print $2'})echo "${VALUE} for ${NAME} is varied by ${DIFF_PERC}%">>${ALERT_FILE}fifidoneif [ $ALERT -ne 0 ]; thensendEmail -f build@shop2020.in -t anikendra.das@shop2020.in amit.gupta@shop2020.in -u "Alert: At least one parameter exceeded their threshold value" -s smtp.gmail.com:587 -xu build@shop2020.in -xp cafe@nes -a ${OUT_FILE} ${OUT_FILE_OLD} -o tls=yes message-file=${ALERT_FILE}exit 1fifi