Skip to content

Instantly share code, notes, and snippets.

@ToroNZ
Created January 15, 2019 01:39
Show Gist options
  • Save ToroNZ/c64597d00447e32d243f4d74a53271ea to your computer and use it in GitHub Desktop.
Save ToroNZ/c64597d00447e32d243f4d74a53271ea to your computer and use it in GitHub Desktop.
watch nfs logs
#!/bin/bash
# Author: Matt Owens <mowens@redhat.com>
#
# This script watches for messages in a specific log file
#
pids=$$
FILE="$1"
PIPE="$2"
checkmessages_DEFAULT=("${@: +3}")
length=$(expr `echo ${#checkmessages_DEFAULT[@]}` - 1)
logfound=false
#text formats
bold="\033[1m"
normal="\e[0m"
endColor='\e[0m'
red='\e[0;31m'
yellow='\e[0;33m'
function find_message() {
while read line < $PIPE; do
for ((i=0; i<=$length; i++)); do
test=$(echo $line | grep -F "${checkmessages_DEFAULT[$i]}" -o)
if [[ "$test" == "${checkmessages_DEFAULT[$i]}" ]]; then
echo "$line"
logfound=true
fi
done
if [[ $logfound == true ]]; then
break
fi
done
}
if [[ ! -p $PIPE ]]; then
mkfifo $PIPE
fi
`tail -n 0 -f $FILE >> $PIPE` &
`find_message &> /tmp/foundmessage.txt`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment