Subversion Repositories SmartDukaan

Rev

Rev 11452 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4855 amit.gupta 1
#!/bin/bash
2
 
3
# resolve links - $0 may be a softlink
4
PRG="$0"
5
 
6
while [ -h "$PRG" ]; do
7
  ls=`ls -ld "$PRG"`
8
  link=`expr "$ls" : '.*-> \(.*\)$'`
9
  if expr "$link" : '/.*' > /dev/null; then
10
    PRG="$link"
11
  else
12
    PRG=`dirname "$PRG"`/"$link"
13
  fi
14
done
15
 
16
 
17
echo "======================================================="
18
echo "Get the scp/rsync snapshot and mysql table migration snapshot."
19
echo "======================================================="
20
 
21
# Get standard environment variables
22
PRGDIR=`dirname $(readlink -f "$PRG")`
23
 
24
hinit() {
25
    mv ${PRGDIR}/hashmap.new ${PRGDIR}/hashmap.old
26
}
27
 
28
hput() {
29
    echo "$1 $2" >> ${PRGDIR}/hashmap.new
30
}
31
 
32
hget() {
33
    grep "^$2 " ${PRGDIR}/hashmap.$1 | awk '{ print $2 };'
34
}
35
 
36
hiterate() {
37
	awk '{ print $1 };' ${PRGDIR}/hashmap.$1
38
}
39
 
40
cd ${PRGDIR}
41
CATALOG_FILE=`ls -t partial-catalog-*.sql | head -n 1`
42
MYSQL_DUMP="${PRGDIR}/${CATALOG_FILE}"
43
EXPORT_PATH="/var/lib/tomcat6/webapps/export"
44
ALL_RSYNC_DIRS="${EXPORT_PATH}/media ${EXPORT_PATH}/media/website ${EXPORT_PATH}/media/static ${EXPORT_PATH}/documents"
45
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}"
46
PROJECT_DIR="`dirname ${PRGDIR}`"
47
OUT_FILE="${PRGDIR}/catalog_info.txt"
48
OUT_FILE_OLD="${PRGDIR}/catalog_info_old.txt"
49
COMP_FILES=1
50
ALERT=0
51
ALERT_FILE=${PRGDIR}/alert.txt
52
 
53
#Empty the alert file
54
echo > ${ALERT_FILE}
55
 
56
#Before getting started move OUT_FILE to OUT_FILE_OLD
57
# also init the hashmap
58
`hinit`
59
 
60
if [ -f ${OUT_FILE} ];
61
then
62
	cat ${OUT_FILE} > ${OUT_FILE_OLD}
63
else 
64
	echo "Could not find the yesterday's validation file. Comapsions cant be performed"
65
	COMP_FILES=0
66
fi
67
 
68
echo -e "Resource name\tSize\tDir Count\tFile Count" > ${OUT_FILE}
69
 
70
for DIR in ${ALL_RSYNC_DIRS}
71
do
72
        cd ${DIR}
73
        FILE_COUNT="$(find ${DIR} -maxdepth 1 -type f | wc -l)"
74
        DIR_COUNT="$(find ${DIR} -maxdepth 1 -type d | wc -l)"
75
        DIR_SIZE="$(du -k --max-depth 0| awk {'print $1'})"
76
	hput "${DIR}|FILE_COUNT" ${FILE_COUNT}
77
	hput "${DIR}|DIR_COUNT" ${DIR_COUNT}
78
	hput "${DIR}|DIR_SIZE" ${DIR_SIZE}
79
        echo -e "${DIR}\t${DIR_SIZE}\t${DIR_COUNT}\t${FILE_COUNT}" >> ${OUT_FILE}
80
done
81
 
82
for FILE in ${ALL_SCP_FILES}
83
do
84
	FILE_SIZE=$(ls -la ${FILE} | awk {'print $5'})
85
	echo -e "${FILE}\t${FILE_SIZE}" >> ${OUT_FILE}
4895 amit.gupta 86
	FILE=${FILE/\-[0-9][0-9][0-9][0-9]*/}
4855 amit.gupta 87
	hput "${FILE}|FILE_SIZE" ${FILE_SIZE}
88
done
89
 
90
#get the items count from the mysql server
91
PAUSED_ITEMS=$(mysql -s --skip-column-names -uroot -pshop2020 catalog -e "select count(*) from item where status = 2")
92
ACTIVE_ITEMS=$(mysql -s --skip-column-names -uroot -pshop2020 catalog -e "select count(*) from item where status = 3")
93
echo "Active items=${ACTIVE_ITEMS}" >> ${OUT_FILE}
94
echo "Paused items=${PAUSED_ITEMS}" >> ${OUT_FILE}
95
hput "ACTIVE_ITEMS_COUNT|NUMBER" ${ACTIVE_ITEMS}
96
hput "PAUSED_ITEMS_COUNT|NUMBER" ${PAUSED_ITEMS}
97
 
4895 amit.gupta 98
if [ ${COMP_FILES} -ne 0 ]; then
4855 amit.gupta 99
	for KEY in `hiterate old`
100
	do
101
		NEW_VAL=`hget "new" ${KEY}`
102
		OLD_VAL=`hget "old" ${KEY}`
103
		if [ ${OLD_VAL} -gt 0 ]; then
104
			DIFF=$(echo "${NEW_VAL} - ${OLD_VAL}"|bc|awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
4904 amit.gupta 105
			DIFF_PERC=$(echo "scale=2;(${DIFF}*100)/${OLD_VAL}" |bc|awk '{printf "%.2f", $0}')
18560 amit.gupta 106
			if [ $(echo ${DIFF_PERC} | tr "." " "| awk {'print $1'}) -ge 10 ]; then
4855 amit.gupta 107
				ALERT=1
108
				NAME=$(echo ${KEY} | tr "|" " "| awk {'print $1'})
109
				VALUE=$(echo ${KEY} | tr "|" " "| awk {'print $2'})
4872 amit.gupta 110
				echo "${VALUE} for ${NAME} is varied by ${DIFF_PERC}%">>${ALERT_FILE}
4855 amit.gupta 111
			fi
112
		fi
113
	done
4895 amit.gupta 114
	if [ $ALERT -ne 0 ]; then
18560 amit.gupta 115
		sendEmail -f build@shop2020.in -t 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}
4888 amit.gupta 116
		exit 1
4877 amit.gupta 117
	fi
4855 amit.gupta 118
fi
119
 
120
 
121
 
122