LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-01-2006, 10:54 AM   #1
omega71122
Member
 
Registered: Mar 2005
Location: Central Ohio, USA
Distribution: Fedora 7 x86_64 (home server), IPCop (home gateway), CentOS (work laptop), lots more at work.
Posts: 32

Rep: Reputation: 15
Removing non-unique record in nawk


Hi all,

We have our Windows clients configured to report to a UNIX syslog server. We want to parse that log file using nawk to keep a list of who is logged on. The list is going to be in a plain-text file. What I need to be able to do is remove only one entry from the file that is not unique using nawk and any system commands or utilities available. Example input from the file:

Code:
Apr-28-machine-logon-jsmith
Apr-28-machine-logon-jsmith
Apr-28-machine-logon-jsmith
The script then sees this line in the log file it parses:
Code:
Apr-28-machine-logoff-jsmith
and we want it to remove only one instance of the corresponding logon entry, leaving the other 2, so that when
Code:
Apr-28-machine-logoff-jsmith
Apr-28-machine-logoff-jsmith
shows up in the log file it parses, it will remove the other 2.

Basically, we want the script to only remove one instance of the "logon" entry for each logoff entry. I've looked at sort, uniq, nawk, and a few other methods, without ideas. What does that community have to say?

Thanks everyone!

Last edited by omega71122; 04-30-2007 at 02:56 PM.
 
Old 05-01-2006, 05:46 PM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Okay, so exactly what is the spec? Let me see if I got it straight: For each line in the input file, if it hasn't been output before, output it.

If that's the effect you want, the following python script does it:

Code:
#!/usr/bin/python
try: set
except NameError: from sets import Set as set
from sys import stdin, stdout

lines = set()
for line in stdin:
    if line not in lines:
        lines.add(line)
        print line,
save it as script.py, then run it as "python script.py < inputfile". Or change the hash-bang path and chmod +x it, and run it as "/path/script.py < inputfile". It should work with both python 2.3 and 2.4

hth --Jonas
 
Old 05-02-2006, 09:38 AM   #3
omega71122
Member
 
Registered: Mar 2005
Location: Central Ohio, USA
Distribution: Fedora 7 x86_64 (home server), IPCop (home gateway), CentOS (work laptop), lots more at work.
Posts: 32

Original Poster
Rep: Reputation: 15
Basically we want the the file the script creates (/var/log/currentusers) to contain only logon entries. When the script sees a logoff entry in the syslog file (in this case /var/log/windowslog/current), we want it to remove an instance of the corresponding logon in the currentusers file. In the end, we want to be able to look at the currentusers file to quickly tell who's logged on.

I wish there was a way I could call nawk recursively...
 
Old 05-02-2006, 09:43 AM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Ah. I misunderstood that, then.

Have a look at who, w, utmp and wtmp. Will they do the job?
 
Old 05-03-2006, 10:45 AM   #5
omega71122
Member
 
Registered: Mar 2005
Location: Central Ohio, USA
Distribution: Fedora 7 x86_64 (home server), IPCop (home gateway), CentOS (work laptop), lots more at work.
Posts: 32

Original Poster
Rep: Reputation: 15
Currently we use who, but due to samba sessions that tend to "hang" (as in they stay active after the user logs out), we're looking for something a bit more accurate.
 
  


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
Removing partially unique lines lluciano Programming 9 01-11-2006 11:20 AM
Nawk output omega71122 Solaris / OpenSolaris 3 08-16-2005 03:40 PM
nawk not available raees Linux - Software 3 05-02-2005 03:49 PM
Nawk issues michedlp Programming 1 02-25-2004 07:29 PM
removing grub from the Master boot record olubone Linux - Software 1 11-16-2003 03:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:15 AM.

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