nginx按時間切割

2022-03-22 04:17:46 字數 1193 閱讀 8590

幾個簡單的切割指令碼:

nginx日誌按天進行切割,通過寫shell指令碼,建立以日期命名檔案

#!/usr/bin/env bash

set -e

# 定義nginx 日誌路徑

log_path="/var/gb/logs/"

# 定義nginx 訪問日誌檔名稱

access_log="access.log"

error_log="error.log"

for i in `find $log_path -name "$access_log"`; do

cd $(dirname $i)

# 切割access日誌

if [[ -f $access_log ]]; then

cp $

: > $access_log

fi# 如果error日誌》20m,切

if [[ -f $error_log ]]; then

error_size=`ls -l $error_log | awk ''`

if [[ $error_size -gt 20971520 ]]; then

cp $

: > $

fifi

done

# 查詢nginx 日誌目錄下7天前的日誌並刪除

find $ -type f -name "*-$" -mtime +7 -delete

find $ -type f -name "*-$" -mtime +7 -delete

其實上面的這個指令碼是有點問題的。就是上面的cp命令,因此存在丟失日誌的風險,可能就是那0.01秒的日誌。

logs_path=/usr/local/nginx/logs/history

cur_logs_path=/usr/local/nginx/logs

yesterday=$(date -d "yesterday" +%y-%m-%d)

mv $/access.log $/access_$.log

mv $/error.log $/error_$.log

## 像nginx主程序傳送usr1訊號,usr1訊號是重新開啟日誌檔案

kill -usr1 $(cat /usr/local/nginx/logs/nginx.pid)

usr1是切割日誌的,對應reopen命令。

MySQL按時間分組

select from unixtime time y m d as time from 表名 where 1 group by time 如果需要詳細資訊,再遍歷時間獲取 類似這種形式 這個是我在工作中的乙個頁面展示 from unixtime的語法 from unixtime unix time...

ls 按時間排序

在linux系統中,使用ls命令按時間排序檔案,其實很簡單,如下 ls altr 即可按時間排序當前目錄下的檔案。附,ls命令的引數中文詳解 a 列出目錄下的所有檔案,包括以 開頭的隱含檔案。b 把檔名中不可輸出的字元用反斜槓加字元編號 就象在c語言裡一樣 的形式列出。c 輸出檔案的 i 節點的修改...

find 按時間查詢

分類 linuxshell日記 mtime 修改時間 ctime 改變時間 atime 訪問時間 mtime 5 至少5天之前修改過的檔案,至少5天沒修改過 mtime 5 5天之內修改過的檔案 mtime 5 剛好5天前修改的檔案 perm 按許可權查詢 perm 001 精確匹配許可權。perm...