Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. filename=`basename $1`
  2. min_seconds=${2:-100}
  3.  
  4. if [ ${filename: -3} == ".gz" ] ; then
  5. cat="zcat"
  6. date=`echo $filename | awk 'match($0, /hiveserver2Interactive.log.([0-9-]+)_.*.gz/, a) {print a[1]}' `
  7. else
  8. cat="cat"
  9. date=`date -I`
  10. fi
  11.  
  12. declare queries=$($cat $filename | awk -v fname=$filename -v min_seconds=$min_seconds 'match($0, /queryId=([a-zA-Z_0-9-]+).*Time taken: +([0-9.]+)/, a) { if (a[2] > min_seconds) { print fname, a[1], a[2] }}')
  13.  
  14.  
  15. if [ -z "$queries" ] ; then
  16. exit 0
  17. fi
  18.  
  19. while read -r line; do
  20. # sample line: hiveserver2Interactive.log.2018-12-04_1.gz hive_20181204021011_06d9474f-587c-4f36-9456-85a568c9919a 4660.311
  21. params=( $line )
  22. filename=${params[0]}
  23. queryId=${params[1]}
  24. queryTime=${params[2]}
  25.  
  26. queryString=$($cat "$filename" | sed -n "/Compiling command(queryId=$queryId)/,/$date/{
  27. s/.*Compiling command(queryId=$queryId): \(.*\)/\1/
  28. /$date/!p
  29. }"
  30. echo ";"
  31. )
  32. echo "$filename", "$queryId", "$queryTime" , "${queryString}" | tr "\n" " "
  33. echo ""
  34. done <<< "${queries%x}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement