Subversion Repositories SmartDukaan

Rev

Rev 4872 | Go to most recent revision | Details | 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
LOG_DIR="/var/log/content-generation"
48
MYSQL_DUMP="${PRGDIR}/partial-catalog-${DATE}.sql"
49
CONTENT_LOG="${LOG_DIR}/content-generation-${DATE}.log"
50
COMPARISON_LOG="${LOG_DIR}/comparison-score-computation-${DATE}.log"
51
PRODUCT_LIST_LOG="${LOG_DIR}/product-list-${DATE}.log"
52
HELPDOCS_LOG="${LOG_DIR}/helpdocs-generation-${DATE}.log"
53
IR_LOG="${LOG_DIR}/irdata-generation-${DATE}.log"
54
SOLR_IRDATA=/var/lib/tomcat6/webapps/export/solr/
55
OUT_FILE="${PRGDIR}/catalog_info.txt"
56
OUT_FILE_OLD="${PRGDIR}/catalog_info_old.txt"
57
COMP_FILES=1
58
ALERT=0
59
ALERT_FILE=${PRGDIR}/alert.txt
60
 
61
#Empty the alert file
62
echo > ${ALERT_FILE}
63
 
64
#Before getting started move OUT_FILE to OUT_FILE_OLD
65
# also init the hashmap
66
`hinit`
67
 
68
if [ -f ${OUT_FILE} ];
69
then
70
	cat ${OUT_FILE} > ${OUT_FILE_OLD}
71
else 
72
	echo "Could not find the yesterday's validation file. Comapsions cant be performed"
73
	COMP_FILES=0
74
fi
75
 
76
echo -e "Resource name\tSize\tDir Count\tFile Count" > ${OUT_FILE}
77
 
78
for DIR in ${ALL_RSYNC_DIRS}
79
do
80
        cd ${DIR}
81
        FILE_COUNT="$(find ${DIR} -maxdepth 1 -type f | wc -l)"
82
        DIR_COUNT="$(find ${DIR} -maxdepth 1 -type d | wc -l)"
83
        DIR_SIZE="$(du -k --max-depth 0| awk {'print $1'})"
84
	hput "${DIR}|FILE_COUNT" ${FILE_COUNT}
85
	hput "${DIR}|DIR_COUNT" ${DIR_COUNT}
86
	hput "${DIR}|DIR_SIZE" ${DIR_SIZE}
87
        echo -e "${DIR}\t${DIR_SIZE}\t${DIR_COUNT}\t${FILE_COUNT}" >> ${OUT_FILE}
88
done
89
 
90
for FILE in ${ALL_SCP_FILES}
91
do
92
	FILE_SIZE=$(ls -la ${FILE} | awk {'print $5'})
93
	echo -e "${FILE}\t${FILE_SIZE}" >> ${OUT_FILE}
94
	hput "${FILE}|FILE_SIZE" ${FILE_SIZE}
95
done
96
 
97
#get the items count from the mysql server
98
PAUSED_ITEMS=$(mysql -s --skip-column-names -uroot -pshop2020 catalog -e "select count(*) from item where status = 2")
99
ACTIVE_ITEMS=$(mysql -s --skip-column-names -uroot -pshop2020 catalog -e "select count(*) from item where status = 3")
100
echo "Active items=${ACTIVE_ITEMS}" >> ${OUT_FILE}
101
echo "Paused items=${PAUSED_ITEMS}" >> ${OUT_FILE}
102
hput "ACTIVE_ITEMS_COUNT|NUMBER" ${ACTIVE_ITEMS}
103
hput "PAUSED_ITEMS_COUNT|NUMBER" ${PAUSED_ITEMS}
104
 
105
if [ ${COMP_FILES} ]; then
106
	for KEY in `hiterate old`
107
	do
108
		NEW_VAL=`hget "new" ${KEY}`
109
		OLD_VAL=`hget "old" ${KEY}`
110
		if [ ${OLD_VAL} -gt 0 ]; then
111
			DIFF=$(echo "${NEW_VAL} - ${OLD_VAL}"|bc|awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
112
			DIFF_PERC=$(echo "scale=2;(${DIFF}*100)/${OLD_VAL}" |bc)
113
			if [ $(echo ${DIFF_PERC} | tr "." " "| awk {'print $1'}) -ge 5 ]; then
114
				ALERT=1
115
				NAME=$(echo ${KEY} | tr "|" " "| awk {'print $1'})
116
				VALUE=$(echo ${KEY} | tr "|" " "| awk {'print $2'})
117
				echo "ALERT: ${VALUE} for ${NAME} is varied by ${DIFF_PERC}%">>${ALERT_FILE}
118
			fi
119
		fi
120
	done
121
 
122
fi
123
 
124
 
125
 
126