CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
*blonde* Me??? Never - well maybe sometimes

 



Arwen_au
New User

Apr 9, 2002, 4:37 PM

Post #1 of 1 (975 views)
*blonde* Me??? Never - well maybe sometimes Can't Post

I am fairly new at Perl (teaching myself) and have done the following as a bash script but now want to write it in Perl (Im using a Unix System)

echo System Usage Log
echo
echo ---------------------
echo
echo Option A - Shows number of times users have logged into the system
echo -----------------------
echo
grep LOGIN $messages | grep -v FAILED | grep -v ftp | cut -f1 -d[ |
cut -f7 -d" " | sort | uniq -c | sort -rn | more
echo
echo Please push enter to continue
read
echo
echo Option B - Shows 5 most common users
echo ------------------------
echo
grep LOGIN $messages | grep -v FAILED | cut -f1 -d[ | cut -f7 -d" " |
sort | uniq -c | sort -rn | head -5
echo
echo Option C - Shows 5 most common sources
echo --------------------------
last | grep -v tty | gawk '{print $3}' | sort | uniq -c | sort -rn | head -5
echo
echo Press enter to go back to main menu

I want to achieve the above but in Perl - I have managed to get Option A working (see Below) but now
want to do Options B and C in the same format - any suggestions would be appreciated



Option A

#!/usr/bin/perl
open (MESSAGES, "</var/log/messages");
#open (PASSWD, "</etc/passwd");
print "You have just opened the file - Press ENTER to continue\n";
$_=<STDIN>;
while (<MESSAGES>) {
@fields = split (/\s/,$_ );
if ($_ =~ /LOGIN/) {
#Do not include FTP
if ($_ !~ /FTP/) {
#Do not include failed logins
if ($_ !~ /FAILED/) {
print "$fields[12]\n" ;
}
}
}
}
close MESSAGES;

OUTPUT WAS

You have just opened the file - Press ENTER to continue

alanc
randall
danieln
danieln
ryanw
ryanw
davidl
richf
brettp
suet
dawnb
dawnb
tonyp
rossw
simong
alanc
mikes
dawnb


SO.....what do I need to do to do (Option B) and (Option C) using the same format I used in (Option A)

I want Option B to show something like this

Option B - Shows 5 most common users
------------------------

52 lynnm
55 tonyg
48 dawnb
47 punnh
42 maryb


I want Option 3 to show

Option C - Shows 5 most common sources
--------------------------
41 c18024.eburwd2.v
26 cppp-p-144-139-5
20 std-lc-106-66.ld
12 std-lc-106-155.l
11 std-lc-106-179.l


I would also like a menu where a user chooses either Option A, B, C

OMG I hope this makes sense


Thank you



Arwen *smile*
OOOOopppppssss Here comes yet another blonde moment *smile*

(This post was edited by Arwen_au on Apr 9, 2002, 6:39 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives