日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux 定时切割日志,Linux 定时切割日志任务

發布時間:2024/4/17 linux 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 定时切割日志,Linux 定时切割日志任务 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

方法一:vi ?/etc/crontab

方法二:crontab -e

系統定時任務配置文件:

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin

MAILTO=root

HOME=/

1 0 * * * /home/logs/Document/rotate_nginx_log.sh

# For details see man 4 crontabs

# Example of job definition:

# .---------------- minute (0 - 59)

# | .------------- hour (0 - 23)

# | | .---------- day of month (1 - 31)

# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...

# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# | | | | |

# * * * * * user-name command to be executed

讓任務生效

設置完成后,重啟cron即可使設置的計劃任務定時執行了,重啟命令如下: 有些linux系統是service cron restart crond服務的重啟命令是 service cron stop service cron start吧 重啟命令:service crond restart 查看任務狀態命令 [root@ovp-l5520-216 binlog]# service crond status crond (pid ?1332) 正在運行...

切割日志腳本:

#!/bin/bash

#

# This script used for rotating NGINX log files.

# Typically, we should setup a Linux CRON job to execute this script periodically.

#

# For example, we setup the following CRON job to rotate NGINX log file at mid night.

# 1 0 * * * ${SCHOOL_ANALYTICS_HOME}/release_current/scripts/rotate_nginx_log.sh

#

# Last modified: 2014.12.12 by XnOU

# the NGINX log file being rotated.

NGINX_LOG=/data/nginx/logs/wuxianji_access.log

# the base directory used to store history log files.

BASE_DIR=/data01/wuxianji/binlog/history_logs

#******************************************************************************

# does the NGINX log file exists?

if [ ! -f ${NGINX_LOG} ]; then

echo "The NGINX log ${NGINX_LOG} does not exists."

exit 1

fi

# extract the first date from the log file.

DATE_STR=`head -8 ${NGINX_LOG} | tail -1 | awk '{print $4}' | awk -F '[' '{print $2}' | awk -F ':' '{print $1}' | sed 's/\//-/g'`

# format "15/Mar/2014" to "2014"

LOG_YEAR=`date -d${DATE_STR} +%Y`

# format "15/Mar/2014" to "20140315"

LOG_DATE=`date -d${DATE_STR} +%Y%m%d`

# the directory used to store history log files.

HISTORY_LOG_DIR=${BASE_DIR}/${LOG_YEAR}

# create directory if not exists.

mkdir -p ${HISTORY_LOG_DIR}

# move the NGINX log file to destination directory.

DEST_FILE=${HISTORY_LOG_DIR}/${LOG_DATE}.log

mv ${NGINX_LOG} ${DEST_FILE}

#echo $DEST_FILE

# grep the master NGINX process and reproduce log files.

NGINX_PID=`ps aux | grep "sbin/nginx" | grep "master process" | awk '{print $2}'`

kill -USR1 ${NGINX_PID}

sleep 1

echo `date "+%Y-%m-%d %H:%M:%S"`

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的linux 定时切割日志,Linux 定时切割日志任务的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。