1. 程式人生 > >工作腳本處理文本

工作腳本處理文本

car export trac $1 port his link 實現 tracking

簡單的使用shell,並且平時學習一下,假設不動手寫的話。真是全然沒有啥用啊。

所以。代碼還是寫出來的。


把下邊的腳本代碼貼出來。怕忘記了。


涉及到數據庫連接,awk使用,日期函數,字符串模糊匹配。


#!/bin/bash

DIR_DATE=`date +"%Y%m%d" -d "-1 days"`
mkdir -p ~/export/$DIR_DATE

myfunc()
{
        for x in $(ls)
        do
                if [ -f "$x" ];then
                       if [[ "$x" =~ music_cgamev2_d* ]] && [[ "$x" =~ .*\.log.1.gz ]];then
                                                        #echo "$x";
                                                        zgrep "LoginGame" $x |grep "info" |awk -F" " ‘{print $2 ":" $3 ":" $9 ":" $10 ":" $11}‘ |awk -F":" ‘{print $1"   "$2":"$3":"$4"  "$6"    "$8"     "$10"    "}‘ >> ~/export/$DIR_DATE/denglu_94_$DIR_DATE.txt
                                                fi
                                                #if [[ "$x" =~ .*\.log.1.gz ]];then
                                                #       echo "$x";
                                                #fi
                elif [ -L "$x" ];then
                        echo "this is a link";
                else
                        cd "$x";
                        myfunc;
                        cd ..
                fi
        done
}

myfunc



#! /bin/bash

DATE=`date +"%Y_%-m_%-d" -d "-1 days" `
DIR_DATE=`date +"%Y%m%d" -d "-1 days"`
mkdir -p /data/cgame/$DIR_DATE
CONN_MYSQL="mysql ~~~~~"


echo "select  * from cgame_history.log_pay_$DATE;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/log_pay_$DATE.txt
echo "select  * from cgame_history.log_money_$DATE;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/log_money_$DATE.txt
echo "select  * from cgame_history.log_items_$DATE;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/log_items_$DATE.txt
echo "select uid, name, jewel, gold, starLevel, chessCount, pay_jewel, pay_gold, FROM_UNIXTIME(traceTime-28800) from card_game.game_player order by traceTime asc;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/player_$DATE.txt

echo "select uid,stone_num,FROM_UNIXTIME( day, ‘%Y%m%d‘ ) as dates from card_game.game_anchor_rank  where FROM_UNIXTIME( day, ‘%Y%m%d‘ ) =$DIR_DATE ORDER BY stone_num desc ;" | $CONN_MYSQL > /data/cgame/$DIR_DATE/anchor_rank_$DATE.txt

echo "select uid,stone_num,FROM_UNIXTIME(day, ‘%Y%m%d‘) as dates from card_game.game_player_rank where FROM_UNIXTIME(day,‘%Y%m%d‘)=$DIR_DATE ORDER BY stone_num desc LIMIT 0,10;"|$CONN_MYSQL > /data/cgame/$DIR_DATE/user_rank_$DATE.txt



寫的不好,僅僅是實現了功能。有些東西都能夠抽出來當做變量, 讓代碼更加可讀。

工作腳本處理文本