bash scripting

A favorite resource:
Another for ifs
More scripting

Here's a snippet of a simple script I wrote recently for checking logs, outputting errors or counting frequency.
can be used like:
   ./cl.sh accepts count
   ./cl.sh accepts

Uses fgrp for faster searching.
Some content changed for privacy reasons.
Can also be piped to file using >output
We plan to put on a chron and could perhaps add in some email alerts



#!/bin/sh

#if passed no param then grep for exception (no case sensitivity, then exit)
if [ $# -eq 0 ]
then
   fgrep -i "Exception" mylog.log
   exit 1
fi

echo "$1 passed as argument, so using that"
echo "$2 2nd argument"

# search for that login exceptions
#
if test $1 == 'login'
then
  search_str='....'

# seach for all rejects
#
elif test $1 == 'rejects'
then
  search_str="..."

# seach for all accepts
#
elif test $1 == 'accepts'
then
  search_str="...."

# soap faults
#
elif test $1 = 'soapfaults'
then
  search_str="SOAP Exception caught"
fi


# Now run the search
#
echo "Searching for: $search_str"
#exit
if [ $# -eq 1 ]
then
  fgrep -i "$search_str" mylog.log
else
  fgrep -c "$search_str" mylog.log
fi




Comments

Popular posts from this blog

deep dive into Material UI TextField built by mui

angular js protractor e2e cheatsheet

react-router v6.4+ loaders, actions, forms and more