本文共 1319 字,大约阅读时间需要 4 分钟。
## exportLog.sh
#!/bin/bash#*/30 * * * * /usr/donica/script/exportLog.shAIRPLANE="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 $FILENAMELAST_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 timefind /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_STRfimkdir -p /usr/tuyue/log/$AIRPLANE##Get Plane ID End##\cp -f /root/cmt_operate_* /usr/tuyue/log/$AIRPLANE/rm /root/cmt_operate_*~
转载地址:http://fbvbi.baihongyu.com/