常用日誌維護指令碼

2022-07-13 08:15:09 字數 3353 閱讀 2011

日誌格式

2015/01/03 22:13:53 [error] 30310#0: open() "/usr/local/nginx/logs/nginx.pid" failed (2: no such file or directory)

2015/01/03 22:15:54 [notice] 31090#0: signal process started

2015/01/03 22:15:54 [error] 31090#0: open() "/usr/local/nginx/logs/nginx.pid" failed (2: no such file or directory)

2015/01/03 22:19:51 [notice] 32601#0: signal process started

2015/01/03 22:19:51 [error] 32601#0: open() "/usr/local/nginx/logs/nginx.pid" failed (2: no such file or directory)

2015/01/03 23:01:51 [notice] 4960#0: signal process started

2015/01/04 13:22:05 [notice] 4644#0: signal process started

2015/01/04 21:08:07 [notice] 7135#0: signal process started

2015/01/11 20:59:24 [notice] 5201#0: signal process started

2015/01/12 23:31:29 [notice] 5121#0: signal process started

1. 列印大於2023年1月3號的日誌

shell> gawk -f '''

}' /usr/local/nginx/logs/error.log

2015/01/04

13:22:05 [notice] 4644#0

: signal process started

2015/01/04

21:08:07 [notice] 7135#0

: signal process started

2015/01/11

20:59:24 [notice] 5201#0

: signal process started

2015/01/12

23:31:29 [notice] 5121#0: signal process started

2. 列印1月3號到1月12號之間的日誌

shell> gawk -f '''

}' /usr/local/nginx/logs/error.log

2015/01/04

13:22:05 [notice] 4644#0

: signal process started

2015/01/04

21:08:07 [notice] 7135#0

: signal process started

2015/01/11

20:59:24 [notice] 5201#0: signal process started

3. 列印當天22:13:53以後的日誌

shell> gawk -f '''

}' /usr/local/nginx/logs/error.log

2015/01/03

22:15:54 [notice] 31090#0

: signal process started

2015/01/03

22:15:54 [error] 31090#0: open() "

/usr/local/nginx/logs/nginx.pid

" failed (2: no such file

or directory)

2015/01/03

22:19:51 [notice] 32601#0

: signal process started

2015/01/03

22:19:51 [error] 32601#0: open() "

/usr/local/nginx/logs/nginx.pid

" failed (2: no such file

or directory)

2015/01/03

23:01:51 [notice] 4960#0: signal process started

4. 列印5分鐘內的日誌

shell> gawk -f '''

}' /usr/local/nginx/logs/error.log

2015/01/03

22:15:54 [notice] 31090#0

: signal process started

2015/01/03

22:15:54 [error] 31090#0: open() "

/usr/local/nginx/logs/nginx.pid

" failed (2: no such file or directory)

5. 每天定時切割nginx日誌指令碼

#!/bin/bash

# this script run at

00:00

# the nginx logs path

logs_path="

/usr/local/webserver/nginx/logs/

"mkdir -p $$(date -d "

yesterday

" +"

%y")/$(date -d "

yesterday

" +"

%m")/

mv $access.log $$(date -d "

yesterday

" +"

%y")/$(date -d "

yesterday

" +"

%m")/access_$(date -d "

yesterday

" +"

%y%m%d

").log

kill -usr1 `cat /usr/local/webserver/nginx/nginx.pid`

設定crontab,每天凌晨00:00切割nginx訪問日誌

crontab -e

輸入以下內容:

引用00

00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

Oracle維護常用指令碼

1 檢視表空間使用情況 select b.file id 檔案id,b.tablespace name 表空間,b.file name 物理檔名,b.bytes 1024 1024 總兆數,b.bytes sum nvl a.bytes,0 1024 1024 已使用m,sum nvl a.byte...

redis集群維護指令碼

redis集群維護 一 啟動100 101上的6個節點 主機 192.168.199.101 cd home redis cluster nodes 7001 執行 nohup home redis 4.0.14 src redis server redis.conf cd home redis c...

MYSQL日誌檔案維護

在 mysql伺服器啟動時,它檢查其命令列的操作,來檢視它是否應該執行登入並開啟相應的日誌檔案 如果應該的話 可以讓伺服器生成兩種主要型別的日誌檔案 常規日誌檔案。它報告客戶機的連線 查詢和其他各種各樣的事件。它對於跟蹤伺服器的活動很有用 誰正在連線 從 連線,以及他們正在做什麼。更新日誌。它報告修...