Bash script for looking in log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script for looking in log file
# 1  
Old 12-08-2015
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:
Code:
/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

Last edited by Don Cragun; 12-08-2015 at 11:59 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 12-08-2015
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
Code:
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

?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-08-2015
Code:
#!/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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] script is filling up my /var/log

I am trying to create a script that checks if my VPN connection is up and running... Everything seems to work as except but for some reason, the script fills up my /var/log/auth.log with the below information Dec 13 01:07:44 debian sudo: soichiro : TTY=pts/0 ; PWD=/home/soichiro/Desktop ;... (5 Replies)
Discussion started by: soichiro
5 Replies

2. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

3. Shell Programming and Scripting

Bash Script Closest Timestamp (LOG FILE)

Hi All, I need something where I could take the date from FILE1 and in this case the date is Thu Sep 10 13:48:42 EDT 2015 and I need it to match the closest PREVIOUS date in the log file FILE2 this means in this specific case it would be Thu Sep 10 2015 13:35:28. I only need the closest... (3 Replies)
Discussion started by: roberto999
3 Replies

4. Shell Programming and Scripting

Bash Script - Mail Secure.log

I'm putting together a fairly simple script, to check "secure.log" for content and email the results in a cron, nightly. The script runs fine upon manual execution, it's a problem when ran in cron. This is on a Mac server. Any thoughts? #!bin/bash #Email secure.log, nightly. Subject="Secure... (6 Replies)
Discussion started by: Nvizn
6 Replies

5. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

6. Shell Programming and Scripting

BASH log file

hi .. am new to bash script.. #!/bin/bash logfile = "${HOME}/log/test.log" ./1.sh echo " script over " can anyone telme hw to set the logfile ?? the above code calls the 1.sh and echo statement gets printed in cmd prompt, but i could not see the log file . (8 Replies)
Discussion started by: Rahul619
8 Replies

7. Shell Programming and Scripting

Bash Script to decrypt encrypt log and archive

Hi Please see if you have come across any aprts of this. I can read, integrate and syntehsixe. Any help you could offer me would be super. thanks in advance! Good day. Thank you for your response in this matter. Here are some further details: 1) scripting is to be in BASH... (1 Reply)
Discussion started by: cdc01
1 Replies

8. Shell Programming and Scripting

how to make my own file as a running log file in bash

Hi, I have written a small script from that iam appending the output to a file.If multiple users invoke the same script or if i invoke the same script n number of times (using &), the output file(ZZ/OUT) contains messup information. #!/bin/bash # echo "Hello" >> /tmp/ZZ/OUT sleep 10 echo... (4 Replies)
Discussion started by: blrguest
4 Replies

9. Shell Programming and Scripting

bunch of ^@^@^@^@^@^@^@^@'s in bash log file

I have a bash script that has been running fine for months that scans a bunch of files and gives me a log file output, it has suddenly started putting 1.5M of a repeating sequence of ^@^@^@^@^@^@^@^@^@^@ on the first line of the logfile, is this a unicode problem I should be setting something in my... (5 Replies)
Discussion started by: unclecameron
5 Replies

10. Shell Programming and Scripting

Logging ALL standard out of a bash script to a log file, but still show on screen

Is it possible to store all standard-out of a bash script and the binaries it calls in a log file AND still display the stdout on screen? I know this is possible to store ALL stdout/stderr of a script to a single log file like: exec 1>&${logFile} exec 2>&1 But running a script with the... (3 Replies)
Discussion started by: ckmehta
3 Replies
Login or Register to Ask a Question