## exportLog.sh
#!/bin/bash
#*/30 * * * * /usr/donica/script/exportLog.sh
AIRPLANE="Default"
TMP1="cmt_operate_"
YEAR=$(date +%Y)
MONTH=$(date +%m)
DAY=$(date +%d)
TMP2=".xls"
FILENAME=${TMP1}${YEAR}${MONTH}${DAY}${TMP2}
FILENAME_MONTH=${TMP1}${YEAR}${MONTH}${TMP2}
#echo $FILENAME
LAST_DAY=`cal $MONTH $YEAR|xargs echo|awk '{print $NF}'`
FILENAME_30="cmt_operate_30days.xls"
MYSQL_PATH='/opt/lampp/bin/mysql'
FLAG='--user=hhwifi --password=donica2012 --database=cmt_wifi'
OPERATE_PATH='/root/'
#delete the files every time
find /usr/tuyue/log -mtime +30 -name "cmt_operate_*" -exec rm -f {} \;
$MYSQL_PATH $FLAG -e "select * from cmt_operate where UNIX_TIMESTAMP( operate_time ) >= UNIX_TIMESTAMP( ) - 60*60*24*30" > $FILENAME_30
$MYSQL_PATH $FLAG -e "select * from cmt_operate where DATE_FORMAT( operate_time, '%Y-%m-%d' ) = DATE_FORMAT( NOW() , '%Y-%m-%d')" > $FILENAME
##Get Plane ID Begin##
PLANE_STR=$($MYSQL_PATH $FLAG -e "select var_value from cmt_config where var_name='system_id' limit 1")
AIRPLANE_STR=$(echo $PLANE_STR | awk '{print $2}')
if [ -z "$AIRPLANE_STR" ]; then
echo ">>>>>>>>[cmt_wifi/cmt_config/system_id] is NULL,please set the flight id for it."
else
AIRPLANE=$AIRPLANE_STR
fi
mkdir -p /usr/tuyue/log/$AIRPLANE
##Get Plane ID End##
\cp -f /root/cmt_operate_* /usr/tuyue/log/$AIRPLANE/
rm /root/cmt_operate_*
~