#!/bin/perl5 -w # $Id: orasum,v 1.2 2000-08-01 10:32:41-05 annis Exp $ # $Source: /u/annis/uw-unix/perltut/RCS/orasum,v $ # # Summarize the Oracle listener logs. use Getopt::Std; use File::Basename; use strict; use vars qw/$opt_s/; sub usage { print STDERR basename($0), " -s \n"; print STDERR "The instance may be 'ALL' to show all data.\n"; exit(1); } # &show_sid_lines($SID, $log_file) - show all matching lines # Where $SID == 'ALL', show all lines. sub show_sid_lines { my ($sid, $file) = @_; open(LOG, "< $file") or die "Cannot open $file: $!"; while() { if (/\(SID=(\w*)\).*\(HOST=([\w\s]*)\)\(USER=(\w*)\)/) { # We found a match... my $SID = $1; my $HOST = $2; my $USER = $3; if ($sid eq "ALL" or $sid eq $SID) { # Now, grab the date... my ($date, $time) = split /\s/, $_, 3; print sprintf("%s %s HOST=%-15s USER=%s\n", $date, $time, $HOST, $USER); } } } close(LOG); } #### MAIN # Get the SID to look at (or ALL), and the log file will remain in # @ARGV. getopt('s:'); if (! $opt_s or $#ARGV < 0) { &usage(); } &show_sid_lines($opt_s, $ARGV[0]); # EOF