Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:57:14+00:00 2026-06-09T01:57:14+00:00

The following bash script sends an email with the PHP error logs for each

  • 0

The following bash script sends an email with the PHP error logs for each day.

#!/bin/bash
 
# phperrlog v1.0
# by vladimir prelovac http://www.prelovac.com/vladimir/
#
# parse error logs on your server and send you daily updates to email
  
# configure options
  EMAIL="tech@domain.com"
   
  WORKDIR="/var/scripts"
  TAIL=50  # number of entries to send
 # IGNORE="/backup" # path to ignore
    
# script starts 'ere
     
 cd $WORKDIR
 rm phperrlog.txt 2>/dev/null
      
 LIST=$(ls /var/log/apache2/*-error.log)
 today=$(date +%Y-%m-%d)
       
 for i in $LIST
  do
    if [ -f $i ]; then
       time=$(date -r $i +%F)
       if [ "$time" == "$today" ]; then
         echo $i >>phperrlog.txt
         echo "---------------------------------" >>phperrlog.txt
         tail -n $TAIL $i >>phperrlog.txt
         echo -e "\n\n\n\n" >>phperrlog.txt
       fi
    fi
 done
                                              
  if [ -f  phperrlog.txt ]; then
    mail -s "PHPERRORLOG SCRIPT: server error logs - $today" $EMAIL  < phperrlog.txt
  fi

How can I modify this script so that it excludes all errors similar to this:

[Thu Aug 02 10:54:33 2012] [error] [client 12.345.67.89] Directory
index forbidden by Options directive:
/var/www/domain/public/templates/img/

[Thu Aug 02 11:25:35 2012] [error] [client 12.345.67.89] client denied
by server configuration:
/var/www/domain/public/templates/sidebar.tpl

I am more interested in the:

  • PHP Notice/Warning/Fatal Errors
  • File does not exist
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:57:15+00:00Added an answer on June 9, 2026 at 1:57 am

    grep can read patterns from a file

     -f file, --file=file
             Read one or more newline separated patterns from file.  Empty
             pattern lines match every input line.  Newlines are not considered
             part of a pattern.  If file is empty, nothing is matched.
    

    In your case you have to decide whether you want to use a whitelist (list of patterns you want to see in your report) or blacklist (list of pattern you don’t want to see). Once you have collected the relevant patterns replace tail -n $TAIL $i >>phperrlog.txt with

    grep -f /path/to/whitelist.txt "$i" | tail -n ${TAIL:-50} >> phperrlog.txt
    

    or

    grep -v -f /path/to/blacklist.txt "$i" | tail -n ${TAIL:-50} >> phperrlog.txt
    

    I would probably start with a blacklist and add additional patterns to it over time when I notice lines I don’t want to see anymore. An initial blacklist could contain

    Directory index forbidden by Options directive
    client denied by server configuration
    

    to mach your samples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following bash script: #!/bin/bash FILE=p.txt while read line; do export http_proxy=http://$line
I've got following bash script to do something for each parameter of the script
I have the following bash script, we can call it script1.sh : #!/bin/bash exec
I have a following bash script: 1 #!/bin/bash 2 query='query= SELECT * WHERE {
following is the bash script I wrote for Sqlite. #!/bin/bash sqlite3 file.db CREATE TABLE
I execute the following bash script: #!/bin/bash version=$1 echo $version sed 's/\${version.number}/$version/' template.txt >
I am facing with the following bash script: #! /bin/bash processname=$1 x=1 while [
Say the following Bash script: #!/bin/bash export TEXTDOMAINDIR=./locale export TEXTDOMAIN=test-gettext-read . gettext.sh echo -n
I am using following script : #!/bin/bash #script to print quality of man #unnikrishnan
Say I have the following Bash script stored in the file foo.sh : #!/bin/bash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.