Re: [PHP] Friday morning brain farts....



On 8/10/07, Robert Cummings <robert@xxxxxxxxxxxxx> wrote:
On Fri, 2007-08-10 at 17:39 +0100, Stut wrote:
Robert Cummings wrote:
On Fri, 2007-08-10 at 11:48 -0400, Daniel Brown wrote:
On 8/10/07, Stut <stuttle@xxxxxxxxx> wrote:
.... I get an email from each
server containing the contents of the error log from the previous day
and my first task each day is to go through that and track down any
issues that usage has highlighted.
That's actually a good point there that I can take away from this.
I actually don't have anything set to send me a log of code issues,
only when an error is caused (and, of course, anything server-related,
but that's a different point entirely).

Simple enough... put the following in a file, and add a cron job.

#!/usr/bin/php -qC
<?php

if( !isset( $argv[1] ) || !isset( $argv[2] ) || !isset( $argv[3] ) )
{
echo "Usage: {$argv[0]} <subject> <email> <path>\n";
exit( 1 );
}

$subject = $argv[1];
$email = $argv[2];
$path = $argv[3];

$content = implode( '', file( $path ) );

if( trim( $content ) === '' )
{
$content = 'NO ERRORS TODAY!!!';
}

mail( $email, $subject, $content );

?>

I used to have something similar to this until someone uploaded a script
that started writing to the error log like mad. Overnight my poor little
script tried to load a 240meg log file into memory and email it to me. I
now use a simple bash script that pipes the log to the mail command -
much safer.

Should probably say that it also renames the log file, graceful's
Apache, zips the old log and moves it to an archive file server. Rob's
script above, used without something that starts a new log will result
in ever-increasing emails.

Oh yeah, that's true-- totally forgot to wipe the error log. I just
whipped the above up :) I have something else on the server without
command line params that I wrote ages ago :) As for a huge file, unless
you set PHPs memory high it should just bail with a fatal memory
exhaustion error. A better script would gzip the log file and attach it
to an email.

Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...........................................................


Wouldn't it even be a worthwhile idea to simply include the first
$n lines of the daily log in an email? That's how I have my logs
emailed to me for the server things. I receive the first 300 lines of
the file, and if there's more than that (which, for server logs, there
always are, because I monitor everything), then I know to either hop
on the server and `vim` the log or download it and read it.

In any case, rotating and archiving would be a requirement.
Depending on the log, mine generally rotate daily or once every three
days, with backups being maintained for at least 30 days.

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Hey, PHP-General list....
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.
.



Relevant Pages

  • Re: Memory consumption PowerShell
    ... Why need a running CMD.Exe on Windows Server 2003 only 144 KB??? ... With best regards ... And we could initiate to run a script oout side the IDN 3.0. ... memory. ...
    (microsoft.public.windows.server.scripting)
  • Re: script dies yet there are no errors in error log
    ... The server encountered an internal error or misconfiguration and was ... no errors show up in PHP error log. ... If I run the "top" command while this script is executing, ... This is true even if I run it against UPCs ...
    (comp.lang.php)
  • Re: ANY Win32_Printer query leaks ~500kbytes in wmiprvse.exe
    ... I can't repro this problem you are describe below is all, ... All the script does below is put the remote server into a loop and does what ... >> Use of memory by Windows is much more complex than most of us know about. ...
    (microsoft.public.win32.programmer.wmi)
  • Re: Reboot command no longer works in Task Scheduler
    ... You can script it. ... Fixing the memory leak and blue screen stop error makes the best sense to me. ... Server event viewer log file, if there are IDs such as 8250, 8026, 2102, then ...
    (microsoft.public.win2000.general)
  • Re: Out of Memory!
    ... My script is running on WinXP, Dos shell, which is a server program. ... unless it will pops-up a "Out of Memory!" ... Could someone tell me this error message is coming from Perl? ...
    (perl.beginners)