快速查找日誌文件最後一行及某個時間段的日誌

           查看最後日誌文件的最後一行:

        sed -n '$p' /var/log/zabbix/zabbix_server.log
239738:20210706:102835.335 Zabbix agent item "perf_counter_en["\PhysicalDisk(0 C: D:)\Avg. Disk Read Queue Length",60]" on host "WIN-202" failed: another network error, wait for 15 seconds

        查看某個時間段(此時間段必須是日誌文件裏面包含的,如果不包含則會查不到任何內容)內的日誌內容:

[root@localhost zabbix]# sed -n '/20210706:100002/,/20210706:102139/p' zabbix_server.log
239738:20210706:100002.381 Zabbix agent item "vm.memory.size[used]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:100017.408 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:100021.418 Zabbix agent item "service.info["TrkWks",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:100040.428 Zabbix agent item "perf_counter_en["\PhysicalDisk(0 C: D:)\Avg. Disk Write Queue Length",60]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:100059.437 Zabbix agent item "service.info["Dhcp",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:100120.459 temporarily disabling Zabbix agent checks on host "WIN-202": host unavailable
239738:20210706:100220.494 enabling Zabbix agent checks on host "WIN-202": host became available
239738:20210706:100224.500 Zabbix agent item "service.info["FontCache",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:100243.509 Zabbix agent item "service.info["RpcEptMapper",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:100258.524 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:100302.555 Zabbix agent item "service.info["LanmanWorkstation",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:100318.573 resuming Zabbix agent checks on host "WIN-202": connection restored

           查看從指定行數到最後一行的內容:

sed -n '11900,$p' zabbix_server.log  -- 11900行,$p 最後一行

239738:20210706:102143.039 resuming Zabbix agent checks on host "WIN-109": connection restored
239738:20210706:102154.056 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102158.067 Zabbix agent item "service.info["SENS",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102217.075 Zabbix agent item "service.info["EventSystem",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:102233.640 resuming Zabbix agent checks on host "WIN-202": connection restored
239735:20210706:102239.497 Zabbix agent item "service.info["LanmanServer",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102254.677 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102258.688 Zabbix agent item "service.info["DiagTrack",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102317.697 Zabbix agent item "vfs.fs.size[C:,used]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:102332.717 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102336.724 Zabbix agent item "perf_counter_en["\PhysicalDisk(1 E:)\Disk Reads/sec",60]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102351.749 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102358.779 Zabbix agent item "service.info["lmhosts",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102416.799 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102420.809 Zabbix agent item "service.info["LanmanWorkstation",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102436.184 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102440.190 Zabbix agent item "service.info["LanmanWorkstation",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102459.220 Zabbix agent item "service.info["NlaSvc",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:102514.238 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102518.249 Zabbix agent item "perf_counter_en["\PhysicalDisk(0 C: D:)\Avg. Disk Read Queue Length",60]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102534.910 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102538.941 Zabbix agent item "service.info["NlaSvc",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102553.986 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102558.004 Zabbix agent item "perf_counter_en["\System\Threads"]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102612.024 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102616.127 Zabbix agent item "perf_counter_en["\PhysicalDisk(1 E:)\Avg. Disk Write Queue Length",60]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102635.136 Zabbix agent item "perf_counter_en["\PhysicalDisk(1 E:)\% Disk Time",60]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:102654.589 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102658.594 Zabbix agent item "service.info["SafeDogCloudHelper",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102717.609 Zabbix agent item "service.info["SafeDogGuardCenter",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:102732.634 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102736.640 Zabbix agent item "service.info["BFE",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102755.649 Zabbix agent item "service.info["nsi",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:102810.677 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:102816.316 Zabbix agent item "service.info["SafeDogGuardCenter",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:102835.335 Zabbix agent item "perf_counter_en["\PhysicalDisk(0 C: D:)\Avg. Disk Read Queue Length",60]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:102854.343 Zabbix agent item "perf_counter_en["\PhysicalDisk(0 C: D:)\Current Disk Queue Length",60]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:102913.363 temporarily disabling Zabbix agent checks on host "WIN-202": host unavailable
239738:20210706:103221.692 enabling Zabbix agent checks on host "WIN-202": host became available
239738:20210706:103225.716 Zabbix agent item "system.swap.size[,total]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:103241.238 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:103245.249 Zabbix agent item "perf_counter_en["\PhysicalDisk(1 E:)\Avg. Disk sec/Write",60]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:103304.257 Zabbix agent item "service.info["PlugPlay",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:103323.277 Zabbix agent item "vfs.fs.size[D:,used]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:103339.829 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:103343.847 Zabbix agent item "service.info["SamSs",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:103402.856 Zabbix agent item "agent.ping" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:103417.869 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:103421.876 Zabbix agent item "service.info["SQLSERVERAGENT",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:103438.533 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:103442.551 Zabbix agent item "service.info["NlaSvc",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:103501.560 Zabbix agent item "system.uptime" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:103516.573 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:103520.579 Zabbix agent item "perf_counter_en["\PhysicalDisk(1 E:)\Avg. Disk Write Queue Length",60]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:103539.594 Zabbix agent item "perf_counter_en["\PhysicalDisk(1 E:)\Avg. Disk Read Queue Length",60]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:103554.613 resuming Zabbix agent checks on host "WIN-202": connection restored
239738:20210706:103559.892 Zabbix agent item "service.info["SQLBrowser",state]" on host "WIN-202" failed: first network error, wait for 15 seconds
239738:20210706:103618.900 Zabbix agent item "service.info["Safedog Update Center",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:103637.915 Zabbix agent item "service.info["DPS",state]" on host "WIN-202" failed: another network error, wait for 15 seconds
239738:20210706:103656.932 temporarily disabling Zabbix agent checks on host "WIN-202": host unavailable

         在文件某行後插入新的數據:

[root@localhost ~]# sed -i.bak '/^1111/a 22222222' a.txt       -- a 後爲新行數據
[root@localhost ~]# ll
總用量 20
-rw-------. 1 root root 1117 Mar 25 10:04 anaconda-ks.cfg
-rw-r--r--  1 root root   35 Jul  6 11:08 a.txt
-rw-r--r--  1 root root   26 Jul  6 11:07 a.txt.bak
drwxr-xr-x. 2 root root    6 Mar 25 10:11 Desktop
drwxr-xr-x. 2 root root    6 Mar 25 10:11 Documents
drwxr-xr-x. 2 root root    6 Mar 25 10:11 Downloads
-rw-r--r--. 1 root root 1424 Mar 25 10:05 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Mar 25 10:11 Music
drwxr-xr-x. 2 root root    6 Mar 25 10:11 Pictures
drwxr-xr-x. 2 root root    6 Mar 25 10:11 Public
-rw-r--r--  1 root root  935 Jun 10 11:08 :q
drwxr-xr-x. 2 root root    6 Mar 25 10:11 Templates
drwxr-xr-x. 2 root root    6 Mar 25 10:11 Videos
[root@localhost ~]# cat a.txt
111111111
22222222

111

33333333

 

22222222
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章