LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2005, 09:12 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
Exclamation Processing squid's access.log into a mysql DB


I want to process squid's access.log into a mysql DB so I can use the DB to make proxy's analysis. I think I'll make a cron job that every hour updates the DB so the requests made during the last hour are inserted into the DB.

My feeling is that doing it with a bash script could be a little tedious.

I have read some time ago that PHP can be used as a shell script machine... but in my kubuntu box, I see no php executable... at least, not in the $PATH.

How can I enable it so I can use it?

And can Anybody provide an example of a php-shell script?
 
Old 11-03-2005, 10:08 AM   #2
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
You can run php from the command line, you need to look at installing + configuring php-cgi which you may not already have installed. You simply link you php script in cron to run at whatever times you want. There are some Squid logfile analysers available that you might want to look at first rather than doing your own, check out the squid website.

Anyways, this is what I have running to parse DansGuardian logs into a MySQL database. It's set as Squid log file formatting, but you might need to change some of the row names accordingly:
Code:
 // Set the location of the DansGuardian access.log file
 $fcontents = file ($logfile);
 
 // Clear out all the existing data in the table
 $result = @mysql_query("DELETE FROM dglogs");
 // Make sure that query was formed correctly, otherwise let user know there's a problem
 if (!$result) {
 	echo("<br>Error performing query: " . mysql_error() . ". Please contact the server administrator with details of your actions.");
 	exit();  
 }
 
 // Execute the mySQL query to output the data into the database
 mysql_query($result);
 echo "<br>Done!";
 
 echo "<br><br>Starting to parse DansGuardian access.log file and adding users.";
 echo "<br>Depending on the size of your log file, this could take several minutes...\n\n";
 
 // Run through file and get contents of data ready to output to array
 for($i=0; $i<sizeof($fcontents); $i++) {
 	$line = addslashes(trim($fcontents[$i]));
 	$line = preg_replace("/\s+/", " ", $line);
 
 	// Create new array called '$parsed' based on contents of the DansGuardian access log
         //$parsed = list(,$rfc931,,$time,,$authuser,$request,,,$bytes,$status)=explode(" ", $line);
 	$parsed = list($date,$time,$user,$ip,$request,$result,$status)=explode(" ", $line);
 
         // Create SQL query to insert data from '$parsed' array into mySQL data
 	$result = @mysql_query("INSERT INTO dglogs VALUES ('','$date','$time','$user','$ip','$request','$result','$status')");
 
 	// Make sure that query was formed correctly, otherwise let user know there's a problem
 	if (!$result) {
 		echo("Error performing query: " . mysql_error() . ". Please contact the server administrator with details of your actions.");
 	exit();  }
 
      	// Execute the mySQL query to output the data into the database
      	mysql_query($result);
 
 }
That's set to run each evening at midnight, and then the logs are rotated so tidy things up.
 
Old 11-03-2005, 10:29 AM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
I installed php-cli and it's working perfectly!.

We have a squid log analysis tool installed: sarg.

And it's been very usefull. Now we need a little more information that sarg doesn't provide.. and that would be it.
 
Old 05-12-2013, 03:38 PM   #4
Afsana
LQ Newbie
 
Registered: May 2013
Location: khasmir
Posts: 1

Rep: Reputation: Disabled
Squid Plugin

i am making a plugin for squid server, how this plugin communicate with squid server.
 
  


Reply



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
view squid's cache content zovres Linux - General 2 11-20-2005 08:39 AM
text processing, maintaining a log jonhewer Linux - Newbie 9 08-25-2005 02:24 AM
Squid access.log to MS Access mephitic Linux - Software 0 10-30-2004 04:45 PM
Strange results in /var/log/apache/access.log subt13 Linux - Security 2 08-03-2004 01:21 PM
how to replace IP address with user login id in squid's access log x2000koh Linux - Networking 1 08-20-2002 02:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:59 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