Bash script for looking in log file

Hello,

I'm a beginner in shell scripting. I would really appreciate some help from the forum.
I want to write a small script that will look in apache error log. If it finds the appropriate word. It would execute some commands.

In my case the apache error log is situated in: /usr/local/apache2/logs/error_log

The words that I would like to grep are : Berkeley DB error for filesystem

Only if it finds them then I need to execute the following commands:

/usr/local/apache2/bin/apachectl stop
svnadmin recover /export/data/svn/svnrepo/
cd /export/data/svn/svnrepo/db/
chown svn:svn *
/usr/local/apache2/bin/apachectl start

I will integrate this script in my Xymon Monitoring tool

Thanks

Please use code tags as required by forum rules!

Any attempts/ideas/thoughts from your side?

---------- Post updated at 18:33 ---------- Previous update was at 18:28 ----------

Anyway, how about

if grep "Berkeley DB error for filesystem" /usr/local/apache2/logs/error_log 
  then  /usr/local/apache2/bin/apachectl stop
        svnadmin recover /export/data/svn/svnrepo/
        cd /export/data/svn/svnrepo/db/
        chown svn:svn *
        /usr/local/apache2/bin/apachectl start
  fi

?

1 Like
#!/bin/sh

COLUMN=svn
COLOR=red
svnstatus=`tail -35 /usr/local/apache2/logs/error_log | grep -i "Berkeley DB error for filesystem"

if [ $? -eq 0 ]
    then

    COLOR=red
        MSG="SVN down"
        /usr/local/apache2/bin/apachectl stop
        svnadmin recover /export/data/svn/svnrepo/
        cd /export/data/svn/svnrepo/db/
        chown svn:svn *
        /usr/local/apache2/bin/apachectl stop

elif [ $? -eq 2 ]
    then
        COLOR=yellow
        MSG="Error test"

        
else
        COLOR=green
        MSG="SVN on $(hostname) is working"
        
fi

---------- Post updated at 12:43 PM ---------- Previous update was at 12:41 PM ----------

I'm trying to integrating it in Xymon Monitoring. Thanks for your quick reply RudiC