Subversion Repositories SmartDukaan

Rev

Rev 4877 | Rev 4888 | Go to most recent revision | 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}
86
	hput "${FILE}|FILE_SIZE" ${FILE_SIZE}
87
done
88
 
89
#get the items count from the mysql server
90
PAUSED_ITEMS=$(mysql -s --skip-column-names -uroot -pshop2020 catalog -e "select count(*) from item where status = 2")
91
ACTIVE_ITEMS=$(mysql -s --skip-column-names -uroot -pshop2020 catalog -e "select count(*) from item where status = 3")
92
echo "Active items=${ACTIVE_ITEMS}" >> ${OUT_FILE}
93
echo "Paused items=${PAUSED_ITEMS}" >> ${OUT_FILE}
94
hput "ACTIVE_ITEMS_COUNT|NUMBER" ${ACTIVE_ITEMS}
95
hput "PAUSED_ITEMS_COUNT|NUMBER" ${PAUSED_ITEMS}
96
 
97
if [ ${COMP_FILES} ]; then
98
	for KEY in `hiterate old`
99
	do
100
		NEW_VAL=`hget "new" ${KEY}`
101
		OLD_VAL=`hget "old" ${KEY}`
102
		if [ ${OLD_VAL} -gt 0 ]; then
103
			DIFF=$(echo "${NEW_VAL} - ${OLD_VAL}"|bc|awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
104
			DIFF_PERC=$(echo "scale=2;(${DIFF}*100)/${OLD_VAL}" |bc)
105
			if [ $(echo ${DIFF_PERC} | tr "." " "| awk {'print $1'}) -ge 5 ]; then
106
				ALERT=1
107
				NAME=$(echo ${KEY} | tr "|" " "| awk {'print $1'})
108
				VALUE=$(echo ${KEY} | tr "|" " "| awk {'print $2'})
4872 amit.gupta 109
				echo "${VALUE} for ${NAME} is varied by ${DIFF_PERC}%">>${ALERT_FILE}
4855 amit.gupta 110
			fi
111
		fi
112
	done
4879 rajveer 113
	if [ $ALERT ]; then
114
		sendEmail -f build@shop2020.in -t mandeep.dhir@shop2020.in rajveer.singh@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}
4877 amit.gupta 115
	fi
4855 amit.gupta 116
fi
117
 
118
 
119
 
120