Skip to content

Instantly share code, notes, and snippets.

@theeye-io
Last active May 16, 2017 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theeye-io/b0c6d0b47e39960347fbe65f485f9e27 to your computer and use it in GitHub Desktop.
Save theeye-io/b0c6d0b47e39960347fbe65f485f9e27 to your computer and use it in GitHub Desktop.
Based on a query from oracle database, remove unused and malformed lines and return pretty output
#!/bin/bash
limit=$1
file=$2
echo "Checking $file . Limit $limit"
echo
# remove trash lines and apply format
# output get out in two columns NAME > VALUE
# NOTE: this part of the script
# awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }'
# join together every two consecutive lines
data=$(cat $file | sed '/^$/d' | sed '/^-[- ]*/d' | sed '/^DISPONIBLE.*$/d' | sed '1,5d;/^TABLESPACE.*$/d' | tac | sed '1,4d' | tac | awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }' | awk '{n=split($0,a," "); print a[1],a[3]}')
alert='no'
while read line; do
val="$(echo $line | cut -d" " -f2)"
if [[ $val > $limit ]]; then
# alert
alert='yes'
fi
done <<< "$(echo -e "$data")"
echo "DATA DUMP"
echo "$data"
# THEEYE parses the data as JSON.
json=$(echo "$data" | awk '{split($0,a," "); print "\"" a[1] "\":" a[2]}' | sed 's/$/,/' | sed '1s/^/{/' | sed '$s/,/}/')
if [ $alert == 'yes' ]; then
echo "{\"state\":\"failure\",\"data\":$json}" | tr '\n' ' '
else
echo "{\"state\":\"success\",\"data\":$json}" | tr '\n' ' '
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment