Shell之导出数据库的表为Excel的脚本

## 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_*
~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值