Postgres – check log file for error (debian)

#!/bin/bash

# Location to place backups.
log_file="/var/log/postgresql/postgresql-11-main.log"
temp_file="/tmp/wu_a"
#match="could not establish connection"
match="error"

/usr/bin/tail  -n 100  $log_file > /tmp/test_aa
fgrep -h -i "$match" /tmp/test_aa > $temp_file

# if match found, the temp file size is not zero, send warning email
if [ -s $temp_file ]; then

    # https://unix.stackexchange.com/questions/564593/how-to-add-subject-to-sendmail-function
    {
      echo From: support@test.com
      echo To: to@test.com
      echo Cc: cc@test.com
      echo Subject: database log issue - $match
      echo
      cat $temp_file
    } | /usr/lib/sendmail -t
else
    rm -f $temp_file
fi

https://download.cloudatcost.com/