清理日誌 scripts

beatony發表於2014-06-20

[root@YXT-016 pts]# mkdir /data/log_bak
[root@YXT-016 pts]# chown -R yxtuser. /data/log_bak/
 指令碼內容如下:
 [yxtuser@YXT-016 scripts]$
cat log_dlpt.sh
#!/bin/sh
#scripts for backup tomcat logfile
#last modify at 2014/06/17
######set values######
yestoday=`date -d "1 days ago" +%Y-%m-%d`
bak_dir=/data/lg_bak/  
 
########function cp log file #####
function cp_log
{
cp $log_file $bakfile
 }

########function empty log file####
 function empty_log
{
echo > $log_file
}

###function gzip logfile ####
function gzip_logfile
{
if [ -f $bakfile ];
then gzip $bakfile else exit
fi
 }

####bakup jsonServer log###
baklog_dir=/data/log_bak/dlpt/jsonServer
log_file=/opt/yxt/dlpt/jsonServer/logs/catalina.out
bakfile=$baklog_dir/catalina.out.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

####bakup smsService log ####
baklog_dir=/data/log_bak/dlpt/smsService
log_file=/opt/yxt/dlpt/smsService/logs/catalina.out
bakfile=$baklog_dir/catalina.out.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log


###bakup wap log###
baklog_dir=/data/log_bak/dlpt/wap
log_file=/opt/yxt/dlpt/wap/logs/catalina.out
bakfile=$baklog_dir/catalina.out.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log


###bakup wap log###
baklog_dir=/data/log_bak/dlpt/wm
log_file=/opt/yxt/dlpt/wm/logs/audit/auditIM.log
bakfile=$baklog_dir/auditIM.log.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###bakup wap log###
baklog_dir=/data/log_bak/dlpt/wm
log_file=/opt/yxt/dlpt/wm/logs/proxool/proxool.log
bakfile=$baklog_dir/proxool.log.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###bakup ps log###
baklog_dir=/data/log_bak/dlpt/ps
log_file=/opt/yxt/dlpt/ps/logs/catalina.out
bakfile=$baklog_dir/catalina.out.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###bakup ep-web log###
baklog_dir=/data/log_bak/dlpt/ep-web
log_file=/opt/yxt/dlpt/ep-web/logs/catalina.out
bakfile=$baklog_dir/catalina.out.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log


####bakup PC log###
baklog_dir=/data/log_bak/dlpt/PC
log_file=/opt/yxt/dlpt/PC/logs/catalina.out
bakfile=$baklog_dir/catalina.out.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###bakup op log###
baklog_dir=/data/log_bak/dlpt/op
log_file=/opt/yxt/dlpt/op/logs/catalina.out
bakfile=$baklog_dir/catalina.out.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###bakup sms log#####
baklog_dir=/data/log_bak/dlpt/sms
log_file=/opt/yxt/dlpt/sms/logs/catalina.out
bakfile=$baklog_dir/catalina.out.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###bakup crontabsend log###
baklog_dir=/data/log_bak/dlpt/crontabsend
log_file=/opt/yxt/dlpt/crontabsend/sendlogs/logs.log
bakfile=$baklog_dir/logs.log.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###bakup parseRecord log####
baklog_dir=/data/log_bak/dlpt/parseRecord
log_file=/opt/yxt/dlpt/parseRecord/logs/count.log
bakfile=$baklog_dir/count.log.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

####bakup nginx log####
baklog_dir=/data/log_bak/nginx
log_file=/data/var/log/nginx/access.log
bakfile=$baklog_dir/access.log.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###bakup nginx log###
baklog_dir=/data/log_bak/nginx
log_file=/data/var/log/nginx/error.log
bakfile=$baklog_dir/error.log.$yestoday
mkdir -p $baklog_dir
cp_log
gzip_logfile
empty_log

###drop 30 days ago file ###
find $bak_dir -name "*.gz" -mtime 365 -exec rm -f {} \;

 ++++++++++++++++++++++++++
[yxtuser@szyxtapvm1 nginx]$ crontab -l
*/1 * * * * sh /opt/yxt/dlpt/parseRecord/startup_debug.sh > /dev/null 2>&1
*/5 * * * * sh /opt/yxt/dlpt/crontabsend/bookSend.sh > /dev/null 2>&1
0 2 * * * sh /home/yxtuser/scripts/log_dlpt.sh > /dev/null 2>&1 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22578826/viewspace-1190156/,如需轉載,請註明出處,否則將追究法律責任。

相關文章