简体   繁体   English

Bash脚本从日志文件中的行中提取日期/时间

[英]Bash script to extract date/time from line in log file

I am seeking help to write a script that will get the last line from a log file and obtain the date/time entry of the last line. 我正在寻求帮助来编写脚本,该脚本将从日志文件中获取最后一行并获取最后一行的日期/时间条目。 Then do a comparison from the current date/time to that of the date/time from the last line in the file. 然后将当前日期/时间与文件最后一行中的日期/时间进行比较。 If the time difference is different by 60 minutes the report the process as failed, ie error code 1. 如果时差相差60分钟,则报告过程失败,即错误代码1。

The log file format is: 日志文件格式为:

Feb 11 16:46:01 [8064][8082] ssnotify.cpp:442:Send(): Send notification by mail: EvtType[5] SenderType[0] SenderName[Landing]    
Feb 11 16:50:52 [8064][8081] ssnotify.cpp:442:Send(): Send notification by mail: EvtType[5] SenderType[0] SenderName[Landing]    
Feb 11 17:07:56 [8064][8082] ssnotify.cpp:442:Send(): Send notification by mail: EvtType[5] SenderType[0] SenderName[Landing]    
Feb 11 17:13:58 [8064][8082] ssnotify.cpp:442:Send(): Send notification by mail: EvtType[5] SenderType[0] SenderName[Landing]

使用tail -1获取最后一行,然后使用awk提取第三列(其中包含日期):

tail -1 your_file | awk '{print $3}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM