I just started to learn unix -
need help to write a script to query a logfile and produce the results that
contains a specific word "alarm" for a period from X day to Y day.
I really have no idea how to begin -
please help...
____________________________________________________
# Print out XXX statistics
# Usage
DIR=/xxx/log/
FILE=${DIR}test.log
[ $# = 1 ] && { FILE=$FILE.$1 ; }
#echo "LEGEND: DN-Down ; UP-Up ; DS-Disconnected ; AL-Alert ; FL-Failed\n"
#echo "Device ID DN | UP | DS | AL| FL| Device ID DN | UP | DS | AL| FL|"
#echo "===============|====|====|===|===| ===============|====|====|===|===|"
cat $FILE | awk '
/Alert/ {
spos = index($0,"[") + 1
epos = index($0,"]")
LEN = epos - spos
DEV = substr($0,spos,LEN)
dev[DEV]++
getline;
getline;
getline;
if ( index($0,"Low") ) {
devalert[DEV]++
}
}
END {
for (i in dev ) {
printf "%-10s %4s \n", i, devalert[i]
}
} '