Created
January 15, 2019 01:39
-
-
Save ToroNZ/c64597d00447e32d243f4d74a53271ea to your computer and use it in GitHub Desktop.
watch nfs logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Matt Owens <[email protected]> | |
# | |
# 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