Colin Davis
Colin Davis

Reputation: 61

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.

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]

Upvotes: 0

Views: 2102

Answers (1)

Maroun
Maroun

Reputation: 95958

Use tail -1 to get the last line, then use awk to extract the third column (which contains the date):

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

Upvotes: 1

Related Questions