Monday, November 23, 2020

Unix/linux: how to arithmetic in /bin/sh and grep log based on last hours event happened

 

# calculator

y0=0

y1=0

y2=0

y3=0

t0=0

t1=0

t2=0

t3=0


getdatenow=`date +%Y/%m/%d" "%H`

getdate1hago=`date --date="1 hour ago" +%Y/%m/%d" "%H`

getdate2hago=`date --date="2 hour ago" +%Y/%m/%d" "%H`

getdate3hago=`date --date="3 hour ago" +%Y/%m/%d" "%H`


# processing today loga

y0=`grep "unable to send message to peer," /logs/UL_$yesterday\_*| grep "$getdatenow" | wc -l`

y1=`grep "unable to send message to peer," /logs/UL_$yesterday\_*| grep "$getdate1hago" | wc -l`

y2=`grep "unable to send message to peer," /logs/UL_$yesterday\_*| grep "$getdate2hago" | wc -l`

y3=`grep "unable to send message to peer," /logs/UL_$yesterday\_*| grep "$getdate3hago" | wc -l`


# processing today loga


t0=`grep "unable to send message to peer," /logs/UL_$getdate\_*| grep "$getdatenow" | wc -l`

t1=`grep "unable to send message to peer," /logs/UL_$getdate\_*| grep "$getdate1hago" | wc -l`

t2=`grep "unable to send message to peer," /logs/UL_$getdate\_*| grep "$getdate2hago" | wc -l`

t3=`grep "unable to send message to peer," /logs/UL_$getdate\_*| grep "$getdate3hago" | wc -l`

NUMBER_ERROR_DETECTED=`expr "$y0 + $y1 + $y2 + $y3 + $t0 + $t1 + $t2 + $t3" | bc`



echo $NUMBER_ERROR_DETECTED

1 comment:

Anonymous said...

Best Baccarat to Win with Bitcoin & Real Money | FEBCASINO
If 인카지노 you're looking for a safe and 바카라 사이트 easy way to play with bitcoin, you'll be spoilt for choice as we reveal our top 10 baccarat worrione table.

UNIX: How to print column nicely using printf

[user@hostfwnms1-oam tmp]# cat b.sh printf "%-26s %-19s %-8s %-8s %-s %-s\n" HOSTNAME IP PING SNMPWALK 0-ok 1-fail for i in `cat n...