日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Shell腳本習(xí)題:自動(dòng)化壓縮處理日志文件

Shell處理日志,自動(dòng)保留30天的日志,如果超過14天的日志就自動(dòng)壓縮為gz格式存儲(chǔ)下來,這樣可以節(jié)省磁盤空間,也是定時(shí)備份日志,我這里是以日志文件舉例的,其它的需求也可以自己根據(jù)腳本內(nèi)容做調(diào)整。

10年積累的成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站策劃后付款的網(wǎng)站建設(shè)流程,更有無為免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

#!/bin/sh 
################################################################

# (c) Copyright 2012 Eric. All rights reserved.

#

# Logs expired 30 days.

#

# *cron

# 1 6 * * * /bin/sh /var/app/shell/logs_arrange.sh > /var/app/shell/cron_logs_arrange.log

#

#

#

################################################################

TODAY=`date +%s`

# how many days ago will the logs to be zip

PK_DAYS_AGO=14

PK_DATEDIFF=`expr ${PK_DAYS_AGO} \* 86400`

PK_EXT=gz

# how many days ago will the logs to be removed

DAYS_AGO=30

DATEDIFF=`expr ${DAYS_AGO} \* 86400`

cleanDir(){

directory=$1

if [[ -d ${directory} ]];then

for file in `ls -1 ${directory} | grep -v '.log$'`;

do

ctime=`stat -c %Y ${directory}/${file}`

timediff=`expr ${TODAY} - ${ctime}`

extname=`ls ${directory}/${file} | awk -F '.' '{printf $NF}'`

if [[ ${extname} != ${PK_EXT} ]] ; then

if [[ -f ${directory}/${file} ]] ; then

zipta=`expr ${timediff} - ${PK_DATEDIFF}`

if [[ ${zipta} -gt 0 ]] ; then

echo "Package ${directory}/${file}"

gzip -f ${directory}/${file} > ${directory}/${file}.${PK_EXT}

fi

fi

fi

if [[ -f ${directory}/${file} ]];then

delta=`expr ${timediff} - ${DATEDIFF}`

if [[ ${delta} -gt 0 ]];then

echo "Removing ${directory}/${file}"

rm -rf ${directory}/${file}

fi

fi

done

fi

}

cleanDir "/var/app/logs/webapps/admin"

cleanDir "/var/app/logs/webapps/api"

cleanDir "/var/app/logs/webapps/pos"

分享文章:Shell腳本習(xí)題:自動(dòng)化壓縮處理日志文件
文章地址:http://www.dlmjj.cn/article/dhodpcj.html