[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/05/2009 at 12:54AM PST, ID: 24873730
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

cannot get system to report

Asked by bs98909 in Perl Programming Language, Unix Systems Programming, Linux

Tags: perl system

Looking at this code... what I wanted to do is search on a user in the html access logs.

I can not get the system call to report back anything -- I opted not to try and parse all the logs in perl itself since I didn't know how many there would actually be.

HELP! Sorry the code has soo much code commented out, but you can see I've been trying many different attempts.
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:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
#!/usr/bin/perl -w 
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use CGI; 
my $q = new CGI; 
my $log="/tmp/yyy.txt";
my $command;
my $name; 
showForm();
exit;
 
#############################
sub showForm {
my $html; 
    #$log = "/var/log/httpd/access_log";
    #$log = "/tmp/access_log"; 
	# print search form
	print header( ), start_html("Query Users"), h1("Search"); 
	print start_form( ), p("Which user?", textfield("WHO")); submit( ), end_form( );
	
	# print results of the query if we have someone to look for
	$name = param("WHO");
	if ($name) {
	  print h1("Results for [$name]");
	  	#$command="cp /dev/null $log; grep $name /var/log/httpd/access_log* | grep Members | grep GET >> $log";
		#print p("command= [$command]") if ( $command ); 
	  	#$html = `echo system($command)`;
		
		#print pre($html);
	  	
		#print p("$log exists") if ( -f $log );
		#print p("$log is readable") if ( -r $log );
		#print p("$log DOES NOT EXIST!!") if (! -f $log ); 
		#$html = `ls -l $log`;
		
		#print pre($html);  
	    #open(LOGFILE, "<", "$log")         or die "can't open $log: $! \n";
	    #print p("open log file: [$log]");
	    #while (<LOGFILE>) {
	        #print pre($_) if (/$name/);
	    #}
	    #close(LOGFILE)
		searchLog();
	}
	
	print end_html( );
}
 
#############################
sub searchLog { 
my %AccessedGuestSite = ();
my %AccessedMemberSite = (); 
my %downloaded = ();
my %hosts = ();
my %FilesDownloaded = ();
my $index; 
my ($filename, $host, $ident_user, $auth_user, $date, $time, $time_zone, $method, $url, $protocol, $status, $bytes, $referer, $agent, $rest); 
	#open (LOGFILE, "<$log") || die("ERROR: cannot read $log!");
	open (LOGFILE, "`grep $name /var/log/httpd/access_log* | grep Members | grep GET` | ") || die("ERROR: cannot read pipe!"); 
	#print $q->header; 
	while (<LOGFILE>) {
		chomp(); 
		my $num = $_ =~ tr / / /; # hack to get the number of spaces on the line
		
		if ($num == 9) {
			($host, $ident_user, $auth_user, $date, $time, $time_zone, $method, $url, $protocol, $status, $bytes) = 
			/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.+?) (\S+)\" (\S+) (\S+)$/
		    #or next;
		
		} elsif ($num == 10) {
			($host, $ident_user, $auth_user, $date, $time, $time_zone, $method, $url, $protocol, $status, $bytes, $referer, $agent) = 
			/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.+?) (\S+)\" (\S+) (\S+) \"([^\"]+)\" \"([^\"]+)\"$/
		    #or next;
		} elsif ($num == 11) {
			($host, $ident_user, $auth_user, $date, $time, $time_zone, $method, $url, $protocol, $status, $bytes, $referer, $agent, $rest) = 
			/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.+?) (\S+)\" (\S+) (\S+) \"([^\"]+)\" \"([^\"]+)\" (.*)$/
		    #or next;
		} elsif ($num > 11) {
			($host, $ident_user, $auth_user, $date, $time, $time_zone, $method, $url, $protocol, $status, $bytes, $referer, $rest) = 
			/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.+?) (\S+)\" (\S+) (\S+) \"([^\"]+)\" (.*)$/
		    #or next;
		} else {
			die "unrecognized log format -- space equals '$num' \n\tline[$_]";
		}
		($filename, $host) = split(/:/,$host); 
		++$hosts{$host}; 
		++$AccessedMemberSite{$date} if (( $url =~ /originalimages/i ) || ( $url =~ /html/i ));
		#++$AccessedMemberSite{$date} if ( $url =~ /Members/i );
		++$AccessedGuestSite{$date}  if ( $url =~ /Guests/i );
		
		#if ((( $url =~ /originalimages/i ) || ( $url =~ /images/i ) || ( $url =~ /zip/i )) && ( ! $url =~ /gif/i )) {
		if (( $url =~ /originalimages/i ) || ( $url =~ /zip/i )) {
			++$downloaded{$date};
			#if ( exists $downloaded{$date} ) { $downloaded{$date}++; } else { $downloaded{$date} = 1; }
			++$FilesDownloaded{$url};
		}
		#print $q->br("*** host[$host], ident[$ident_user], auth[$auth_user], date[$date], time[$time], tz[$time_zone], method[$method], url[$url], protocol[$protocol], status[$status], bytes[$bytes], referer[$referer], agent[$agent]");
		#print $q->br("--- rest[$rest]");
		#print $q->hr();
	}	
	print $q->h2("Usage report");
	print $q->h3("-- for user: '$auth_user' from hosts: ");
	### %hosts
	
	foreach (keys %hosts) {
	    ### $_
		print ("$_ x ($hosts{$_}) times ") if (exists $hosts{$_});
	}
	### %AccessedGuestSite
	foreach (keys %AccessedGuestSite) {
	    ### $_
		print $q->p("Accessed GUEST site on $_, $AccessedGuestSite{$_} times, and downloaded $downloaded{$_} bytes") if (exists $AccessedGuestSite{$_});
	}
	### %AccessedMemberSite
	foreach (keys %AccessedMemberSite) {
	    ### $_
		print $q->p("Accessed Members Pages on $_, $AccessedMemberSite{$_} times, and downloaded $downloaded{$_} bytes")  if (exists $AccessedMemberSite{$_});
	}
	print $q->p("Downloaded the following files:");
	foreach (keys %FilesDownloaded) {
	    ### $_
		print $q->p("Downloaded $_ x ($FilesDownloaded{$_}) times") if (exists $FilesDownloaded{$_});
	}
	print $q->p("***** EOF ************");
	close("LOGFILE"); 
} 
__END__
[+][-]11/05/09 05:44 AM, ID: 25749309

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 05:47 AM, ID: 25749343

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 06:58 AM, ID: 25750102

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 07:37 AM, ID: 25750591

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 07:39 AM, ID: 25750622

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 08:53 AM, ID: 25751427

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 05:12 PM, ID: 25755897

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 07:09 AM, ID: 25759723

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 07:11 AM, ID: 25759745

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 08:17 AM, ID: 25760443

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Perl Programming Language, Unix Systems Programming, Linux
Tags: perl system
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625