How to check file have a "SYSTEM" word or not
am 12.09.2007 05:49:09 von moonhk
If SYSTEM does not eixsint in ${DBLOG}, LINES return blank line
LINES=`pr -n ${DBLOG} |grep 'SYSTEM' |tail -1`
If below command good or not ? Any improvement ?
if [ "$LINEONLY" -lt " " ] ; then
[ $LINEONLY > 1 ]
Main program
#!/bin/ksh
#
DBLOG=/database/ph.lg
# Tmp file
TMPFILE01=/home/ericl6/log/checklg.tmp
#
MAILTO_ME ()
{
echo MAILTO_ME
mailx -s "DBLOG ${DBLOG} have New SYSTEM Error" $ME <
cnt -l = $cnt_l
cnt -mmax = $cnt_mmax
`pr -n ${DBLOG} |grep 'SYSTEM'`
*** end of message ***
!
}
grep 'WARNING' ${DBLOG} |grep -v 'WARNING: -l exceed' |grep -v
'WARNING: -mmax exceeded'
cnt_l=`grep 'WARNING: -l exceed' ${DBLOG} |wc -l`
cnt_mmax=`grep 'WARNING: -mmax exceeded' ${DBLOG} |wc -l`
LINEONLY=NULL
LINES=`pr -n ${DBLOG} |grep 'SYSTEM' |tail -1`
LINEONLY=`echo $LINES| awk '{print $1}'`
#~~echo LINEONLY=$LINEONLY
rtn01=1
if [ -f $TMPFILE01 ] ; then
grep "$LONEONLY" $TMPFILE01 > /dev/null
rtn01=$?
else
if [ "$LINEONLY" -lt " " ] ; then
rtn01=1
fi
fi
if [ $rtn01 = 1 ] && [ $LINEONLY > 1 ] ; then
# New SYSTEM ERROR FOUND, Update line number in temp file
echo $LINEONLY > $TMPFILE01
MAILTO_ME
fi
Re: How to check file have a "SYSTEM" word or not
am 12.09.2007 06:44:57 von Barry Margolin
In article <1189568949.359425.166780@50g2000hsm.googlegroups.com>,
moonhk wrote:
> If SYSTEM does not eixsint in ${DBLOG}, LINES return blank line
> LINES=`pr -n ${DBLOG} |grep 'SYSTEM' |tail -1`
>
> If below command good or not ? Any improvement ?
> if [ "$LINEONLY" -lt " " ] ; then
>
> [ $LINEONLY > 1 ]
I would do:
if grep -q SYSTEM "$DBLOG"
then ...
fi
>
> Main program
>
> #!/bin/ksh
> #
> DBLOG=/database/ph.lg
>
> # Tmp file
> TMPFILE01=/home/ericl6/log/checklg.tmp
>
> #
>
> MAILTO_ME ()
> {
> echo MAILTO_ME
> mailx -s "DBLOG ${DBLOG} have New SYSTEM Error" $ME <
>
> cnt -l = $cnt_l
> cnt -mmax = $cnt_mmax
>
> `pr -n ${DBLOG} |grep 'SYSTEM'`
>
> *** end of message ***
> !
> }
>
> grep 'WARNING' ${DBLOG} |grep -v 'WARNING: -l exceed' |grep -v
> 'WARNING: -mmax exceeded'
> cnt_l=`grep 'WARNING: -l exceed' ${DBLOG} |wc -l`
> cnt_mmax=`grep 'WARNING: -mmax exceeded' ${DBLOG} |wc -l`
>
> LINEONLY=NULL
> LINES=`pr -n ${DBLOG} |grep 'SYSTEM' |tail -1`
> LINEONLY=`echo $LINES| awk '{print $1}'`
> #~~echo LINEONLY=$LINEONLY
> rtn01=1
> if [ -f $TMPFILE01 ] ; then
> grep "$LONEONLY" $TMPFILE01 > /dev/null
> rtn01=$?
> else
> if [ "$LINEONLY" -lt " " ] ; then
> rtn01=1
> fi
> fi
> if [ $rtn01 = 1 ] && [ $LINEONLY > 1 ] ; then
> # New SYSTEM ERROR FOUND, Update line number in temp file
> echo $LINEONLY > $TMPFILE01
> MAILTO_ME
> fi
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Re: How to check file have a "SYSTEM" word or not
am 12.09.2007 10:43:59 von moonhk
On 9 12 , 12 44 , Barry Margolin wrote:
> In article <1189568949.359425.166...@50g2000hsm.googlegroups.com>,
>
> moonhk wrote:
> > If SYSTEM does not eixsint in ${DBLOG}, LINES return blank line
> > LINES=`pr -n ${DBLOG} |grep 'SYSTEM' |tail -1`
>
> > If below command good or not ? Any improvement ?
> > if [ "$LINEONLY" -lt " " ] ; then
>
> > [ $LINEONLY > 1 ]
>
> I would do:
>
> if grep -q SYSTEM "$DBLOG"
> then ...
> fi
>
>
>
>
>
>
>
> > Main program
>
> > #!/bin/ksh
> > #
> > DBLOG=/database/ph.lg
>
> > # Tmp file
> > TMPFILE01=/home/ericl6/log/checklg.tmp
>
> > #
>
> > MAILTO_ME ()
> > {
> > echo MAILTO_ME
> > mailx -s "DBLOG ${DBLOG} have New SYSTEM Error" $ME <
>
> > cnt -l = $cnt_l
> > cnt -mmax = $cnt_mmax
>
> > `pr -n ${DBLOG} |grep 'SYSTEM'`
>
> > *** end of message ***
> > !
> > }
>
> > grep 'WARNING' ${DBLOG} |grep -v 'WARNING: -l exceed' |grep -v
> > 'WARNING: -mmax exceeded'
> > cnt_l=`grep 'WARNING: -l exceed' ${DBLOG} |wc -l`
> > cnt_mmax=`grep 'WARNING: -mmax exceeded' ${DBLOG} |wc -l`
>
> > LINEONLY=NULL
> > LINES=`pr -n ${DBLOG} |grep 'SYSTEM' |tail -1`
> > LINEONLY=`echo $LINES| awk '{print $1}'`
> > #~~echo LINEONLY=$LINEONLY
> > rtn01=1
> > if [ -f $TMPFILE01 ] ; then
> > grep "$LONEONLY" $TMPFILE01 > /dev/null
> > rtn01=$?
> > else
> > if [ "$LINEONLY" -lt " " ] ; then
> > rtn01=1
> > fi
> > fi
> > if [ $rtn01 = 1 ] && [ $LINEONLY > 1 ] ; then
> > # New SYSTEM ERROR FOUND, Update line number in temp file
> > echo $LINEONLY > $TMPFILE01
> > MAILTO_ME
> > fi
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***- -
>
> - -
Thank. Tested OK for me.