LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2005, 03:01 AM   #1
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Rep: Reputation: 30
Perl regular expressions (Solved)


Hi,

I am trying to configure swatch, a program that uses regular expressions from perl to analyse log files. When a regular expression in the config file matches a line in a log file it can be showed on the terminal etc. The problem is that I don't know how perl works.

I want for example log the lines with "su" in it. It appears like "su[8957]:" in the log files but the number varies. The "su" line won't get logged if I only use "su" in my swatch config file, I should also use a regular expression from perl to grab the "[number]:" part.

I also want to log lines with "sudo:" in it, but it won't work if I use "sudo" and "sudo:" in my swatch config file, so I am looking for a solution for that also.

Does someone know how I can handle this?

Thanks for your help

Last edited by daYz; 08-05-2005 at 01:48 PM.
 
Old 08-05-2005, 04:56 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,795

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Maybe try /su/ or /su\[\d+\]/ ?
 
Old 08-05-2005, 01:47 PM   #3
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
Thanks for your help. I have discovered that I can use /su*/ to log both su and sudo. Should have tried that earlier.

Last edited by daYz; 08-05-2005 at 01:53 PM.
 
Old 08-07-2005, 06:09 AM   #4
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
Originally posted by daYz
Thanks for your help. I have discovered that I can use /su*/ to log both su and sudo. Should have tried that earlier.
If I understand perl's regexps correctly, you're matching anything with an 's' followed by zero or more occurrences of 'u'. That's fine if that's what you really want, but I'd suggest using /su.*/ which will match "su" followed by anything.
 
Old 08-11-2005, 02:06 AM   #5
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
Thanks for clarifying that eddiebaby1023. What you suggest works fine, but when I also try to log sshd with /sshd.*/ all three su, sudo and sshd don't get logged.

Any suggestions on that?

Thanks
 
Old 08-11-2005, 05:53 AM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,795

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Maybe try :
Code:
/su|sshd/

Last edited by keefaz; 08-11-2005 at 05:55 AM.
 
Old 08-11-2005, 08:27 AM   #7
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
Yes!!!! This seems to work, also for the other things I want to log.

Thanks both of you.

Regards,

Ben
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl regular expressions CyberJedi Programming 2 10-02-2005 12:17 PM
Regular Expressions markjuggles Programming 2 05-05-2005 12:39 PM
Perl and Regular Expressions Fonk Programming 1 06-27-2004 12:32 PM
Perl Regular Expressions true_atlantis Programming 1 11-15-2003 06:16 PM
regular expressions? alaios Linux - General 2 06-11-2003 04:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration