nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Locating string/s in a log file

This is a discussion on Locating string/s in a log file within the Shell scripting forums, part of the Development/Scripting category; Hi, Below is an excerpt of an ossec log file. What I wanted to do is to locate/search a users ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-05-2009, 12:13 PM
Junior Member
User
 
Join Date: Feb 2009
OS: Redhat, Fedora, Suse, Ubuntu, Solaris
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
fluxss is on a distinguished road
Default Locating string/s in a log file

Hi,

Below is an excerpt of an ossec log file. What I wanted to do is to locate/search a users time of log on by:

1. searching the user's uname in the line with "Successful Network Logon"
2. getting the line with the date/time "2009 May 21 09:00:54" just before the line where #1 was retrieved.

Hoping you could help me on this
-------------------------------------------------------------------------
Code:
** Alert 1242867654.171407408: - windows,authentication_success,
2009 May 21 09:00:54 (dc1) 10.11.20.4->WinEvtLog
Rule: 18107 (level 3) -> 'Windows Logon Success.'
Src IP: (none)
User: hostname
WinEvtLog: Security: AUDIT_SUCCESS(540): Security: hostname: PSB: dc1: Successful Network Logon:        User Name: hostname         

** Alert 1242867656.171408138: - windows,
2009 May 21 09:00:56 (filesvr) 10.11.40.108->WinEvtLog
Rule: 18149 (level 3) -> 'Windows User Logoff.'
Src IP: (none)
User: testuser01
WinEvtLog: Security: AUDIT_SUCCESS(538): Security: testuser01: PSB: FILESVR: User Logoff:     User Name: testuser           

** Alert 1242867657.171408505: - windows,authentication_success,
2009 May 21 09:00:57 (ftpsvr) 10.11.40.24->WinEvtLog
Rule: 18107 (level 3) -> 'Windows Logon Success.'
Src IP: (none)
User: testuser02
WinEvtLog: Security: AUDIT_SUCCESS(540): Security: ftpsvr: ftpsr: svr01: Successful Network Logon:      User Name: ftpsvr         

** Alert 1242867658.171408999: - windows,
2009 May 21 09:00:58 (mailsvr) 10.11.41.70->WinEvtLog
Rule: 18149 (level 3) -> 'Windows User Logoff.'
Src IP: (none)
User: testuser03
WinEvtLog: Security: AUDIT_SUCCESS(538): Security: testuser03: PSB: mailsvr: User Logoff:     User Name: testuser03

Last edited by nixcraft; 22-05-2009 at 02:23 AM.
Reply With Quote
  #2 (permalink)  
Old 22-05-2009, 12:49 AM
Member
User
 
Join Date: May 2009
OS: Mandriva
Posts: 78
Thanks: 0
Thanked 14 Times in 14 Posts
Rep Power: 2
cfajohnson has a spectacular aura about cfajohnson has a spectacular aura about
Default

Code:
awk -v name=hostname 'BEGIN {
  FS = "\n" ; RS = ""
  str = name ".*Successful Network Logon"
 }
$0 ~ str { 
  print $2
}'
Reply With Quote
  #3 (permalink)  
Old 11-06-2009, 01:24 PM
Junior Member
User
 
Join Date: Feb 2009
OS: Redhat, Fedora, Suse, Ubuntu, Solaris
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
fluxss is on a distinguished road
Default

Quote:
Originally Posted by cfajohnson View Post
Code:
awk -v name=hostname 'BEGIN {
  FS = "\n" ; RS = ""
  str = name ".*Successful Network Logon"
 }
$0 ~ str { 
  print $2
}'
Can anyone tell me how this script work when running it to the sample log file above?

Thanks.
Reply With Quote
Reply

Tags
awk , awk select lines , shell scripting


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
String manipulation Gideon Shell scripting 19 31-05-2009 01:50 AM
Shell Script for Searching a String vivekv Shell scripting 7 10-03-2009 03:18 AM
split files by specifying a string (bash shell) vikas027 Shell scripting 4 01-11-2007 04:22 PM
linux command search server for string chimu Linux software 2 26-07-2006 12:40 AM
example for string connect to a command. ryan Shell scripting 2 22-02-2005 01:05 PM


All times are GMT +5.5. The time now is 02:26 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38