Skip to content

Instantly share code, notes, and snippets.

@GarimaDamani
Created August 7, 2019 00:29
Show Gist options
  • Save GarimaDamani/98c2edbb439b87a31047c975c7b1c6c0 to your computer and use it in GitHub Desktop.
Save GarimaDamani/98c2edbb439b87a31047c975c7b1c6c0 to your computer and use it in GitHub Desktop.
Shell script to parse particular log file and get the logs based on various patterns of past one minute and write the output to another file
#!/bin/bash/
FILE_PATH=”/var/opt/scripts/past_1min.log”
FETCH_LOG=”/var/opt/jfrog/artifactory/logs/request.log”
while true
do
TIME=$(date — date “-1min” ‘+%Y%m%d%H%M’)
sed -n “/^$TIME/,$ p” $FETCH_LOG > $FILE_PATH
echo -n “$(grep ‘HTTP/1.1|20.|’ $FILE_PATH | wc -l)” > /var/opt/scripts/parse.out.log
echo -n “ $(grep ‘HTTP/1.1|40.|’ $FILE_PATH | wc -l)” >> /var/opt/scripts/parse.out.log
echo -n “ $(grep ‘HTTP/1.1|50.|’ $FILE_PATH | wc -l)” >> /var/opt/scripts/parse.out.log
echo -n “ $(grep ‘|GET|’ $FILE_PATH | wc -l)” >> /var/opt/scripts/parse.out.log
echo -n “ $(grep ‘|PUT|’ $FILE_PATH | wc -l)” >> /var/opt/scripts/parse.out.log
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment