Search Unix Commands/Scripts


  Help us in improving the repository. Add new commands/scripts through 'Submit Commands/Scripts ' link.





Unix Commands/Scripts for '#Awk' - 4 Commands/Scripts found

 Sample 1. Shell Script for Log4j Log Analysis and exception reporting

#!/bin/ksh

EMAIL_SUBJECT="Exceptions-Log"
EMAIL_TO="xyz@yahoo.com"
`grep "xception" Out.log >> /home/xyz/test1`
`cat /home/xyz/test1 | sed -n 's/.* ([^ ]*xception[^ ]*) .*/1/p' | awk '!x[$0]++' >> /home/xyz/test2`

`rm test3`

while read line
do
lineNum=`sed -n "/$line/,/EST/{=;q;}" Out.log`
let bl=$lineNum-5
let el=$lineNum+15
echo "*************************************************
$line
**************************************************

" >> test3
`sed -n "$bl,$el p" Out.log >> test3`
echo "


" >> test3
done < "/home/xyz/test2"

`cat test3 | /bin/mail -s $EMAIL_SUBJECT $EMAIL_TO`

   Like      Feedback     script  exception reporting script  log4j analysis script  awk


 Sample 2. Shell Scripts for Automating System Monitoring Task

#!/bin/ksh

errorSnippet=''

# ********************************************************Configuration***************************************************************
homeBench='90'
VivaBench='90'
rootBench='90'
appHomeBench='90'
idleBench='95'
logsOldBench='15'
memUsageBench='2500'
avgLoadBench='5'
EMAIL_SUBJECT="Server Health Check Report for $(hostname)"
EMAIL_TO="test@test.com"
# ************************************************************************************************************************************

dfHome=`df | sed -n '/ /home$/s/.* ([0-9][0-9]*)%.*/1/p'`
dfViva=`df | sed -n '/ /apphome/Viva$/s/.* ([0-9][0-9]*)%.*/1/p'`
dfRoot=`df | sed -n '/ /$/s/.* ([0-9][0-9]*)%.*/1/p'`
dfApphome=`df | sed -n '/ /apphome$/s/.* ([0-9][0-9]*)%.*/1/p'`
dfLogsOld=`df | sed -n '/ /localvg-logsOld$/s/.* ([0-9][0-9]*)%.*/1/p'`
memUsage=`sar -q 1 | tail -1 | awk '{ print "" $3}' | sed 's/%//g'`
avgLoad=`uptime | awk -F "$FTEXT" '{ print $2 }' | cut -d, -f3`
iostatIdle=`iostat | awk '{print $5}' | awk 'NR==4' | cut -d '.' -f1`

if [[ $dfHome -gt $homeBench ]] then
errorSnippet="Disk Usage for /home exceedeed the benchmark, Its $dfHome now";
fi
if [[ $dfViva -gt $VivaBench ]] then
errorSnippet="$errorSnippet
Disk Usage for /apphome/Viva exceedeed the benchmark, Its $dfViva now";
fi
if [[ $dfRoot -gt $rootBench ]] then
errorSnippet="$errorSnippet
Disk Usage for /(root) exceedeed the benchmark, Its $dfRoot now";
fi
if [[ $dfRoot -gt $rootBench ]] then
errorSnippet="$errorSnippet
Disk Usage for /(root) exceedeed the benchmark, Its $dfRoot now";
fi
if [[ $dfApphome -gt $appHomeBench ]] then
errorSnippet="$errorSnippet
Disk Usage for /apphome exceedeed the benchmark, Its $dfApphome now";
fi
if [[ $dfLogsOld -gt $logsOldBench ]] then
errorSnippet="$errorSnippet
Disk Usage for logs old exceedeed the benchmark, Its $dfLogsOld now";
fi
if [[ $iostatIdle -gt $idleBench ]] then
errorSnippet="$errorSnippet
Iostat idle exceedeed the benchmark, Its $iostatIdle now";
fi
if [[ $memUsage -gt $memUsageBench ]] then
errorSnippet="$errorSnippet
Memory Usage exceedeed the benchmark, Its $memUsage now";
fi
if [[ $avgLoad -gt $avgLoadBench ]] then
errorSnippet="$errorSnippet
15 minute Average Load exceedeed the benchmark, Its $avgLoad now";
fi

print $errorSnippet
if [ "$errorSnippet" != "" ]; then
`echo errorSnippet | /bin/mail -s $EMAIL_SUBJECT $EMAIL_TO`
fi

   Like      Feedback     script to automate monitoring task  df  sed  sar  tail  awk  iostat  shell script if block  print  /bin/mail


 Sample 3. Print last field using awk

awk { print $NF }

   Like      Feedback     awk


 Sample 4. Get fields matching a particular string using awk

awk '/xception/ { print $1 }' source.txt >> destination.txt

   Like      Feedback     awk



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner