Skip to content

Instantly share code, notes, and snippets.

@catchamonkey
Created November 9, 2011 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catchamonkey/1351299 to your computer and use it in GitHub Desktop.
Save catchamonkey/1351299 to your computer and use it in GitHub Desktop.
Mail your Errors during development without Nagios/Ossec
<?php
// during development you can simply have all Error mentions in your logs (presumably you are logging properly?) mailed to you.
// in production you may be using OSSEC/Nagios etc, but this is a quick win for dev.
// to run, you would do something like
// tail -f /var/log/messages |grep Error | php /home/sites/poc/stdInMailer.php
$fp = fopen("php://stdin","r");
while ($line = stream_get_line($fp,65535,"\n"))
{
// output as if normal tail were in flow
echo $line."\n";
// send the mail
mail('catchamonkey@example.com', 'Dev Container Error Mail', $line);
}
fclose($fp);
// alternatively you can do this inline...
tail -f /var/log/messages | grep Error | php -R 'mail("catchamonkey@example.com", "Dev Container Error Mail", $argn);'
// take your pick.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment