zoukankan      html  css  js  c++  java
  • 快速查找日志文件最后一行及某个时间段的日志

               查看最后日志文件的最后一行:

            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["SystemThreads"]" 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
  • 相关阅读:
    ionic环境搭建
    C# Enum Type
    【IOS】3. OC 类声明和实现
    【IOS】2.基础
    【IOS】1.学前准备
    win8, VS2013 .NET 4.5在哪找svcutil.exe?
    【你吐吧c#每日学习】11.10 C# Data Type conversion
    【你吐吧c#每日学习】10.30 C#Nullable Types
    【你吐吧c#每日学习】10.29 C#字符串类型&Common operators
    给三个int,判断是否可构成三角形算法
  • 原文地址:https://www.cnblogs.com/zhongjicainiao/p/14975810.html
Copyright © 2011-2022 走看看