I know that this script is probably a security risk because I am using the system command but what I am trying to do is get the hits of a webpage. They read from the access logs and puts the output into a table. My problem is that it isn't getting the correct number. Each access file is the name of the domain.
system("ls /var/log/apache/access/* > found");
open (INF, "found");
@grok = <INF>;
close(INF);
foreach $i (@grok) {
$i =~ s/.*[\/\\](.*)/$1/;
$count = system("grep -c GET $i");
print "<tr><td><font size=1>$i</font></td><td><font size=1>$count</font></td></tr>";
}
I know that I am only grepping the file when I should be grepping the path and the file but I couldn't get it to all work together. Could somebody see what I am doing wrong. Somebody said that you couldn't put the count from a grep into a variable. Any ideas? I can't use modules as I am in a class learning basic perl and I don't want to get to far ahead with modules. So if possible I would like to use the system command.
system("ls /var/log/apache/access/* > found");
open (INF, "found");
@grok = <INF>;
close(INF);
foreach $i (@grok) {
$i =~ s/.*[\/\\](.*)/$1/;
$count = system("grep -c GET $i");
print "<tr><td><font size=1>$i</font></td><td><font size=1>$count</font></td></tr>";
}
I know that I am only grepping the file when I should be grepping the path and the file but I couldn't get it to all work together. Could somebody see what I am doing wrong. Somebody said that you couldn't put the count from a grep into a variable. Any ideas? I can't use modules as I am in a class learning basic perl and I don't want to get to far ahead with modules. So if possible I would like to use the system command.