-
Notifications
You must be signed in to change notification settings - Fork 1
/
sargrep
executable file
·28 lines (27 loc) · 1.17 KB
/
sargrep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Sargrep-0.0.1 - written by Kyle Walker kwalker@redhat.com
# Should allow you to grab sections of data from a sar file
if [ $# -eq 0 ]; then
echo -e "\tUsage: data <file> <pattern> [max] [min] [option]"
exit
elif [[ -z $4 ]]; then
echo blank 4
set $4=10
elif [[ -z $3 ]]; then
echo blank
set $3=0
set $4=10
elif [[ $5 == '-h' ]]; then
if [[ $2 == "mem" ]]; then
procmem=`awk '/MemTotal/ {print $2}' proc/meminfo`
awk 'BEGIN {CONVFMT="%.1f"; instances = 0; div = '"$procmem"'; max = '"$4"'; min = '"$3"'} /'"$2"'/,/^$/ {if(instances < max && instances >= min && $0 !~/^$/ && $1 !~/00:00/) print $1"\t"$2"\t"$3"\t"$4"\t~"(($5/div)*100)"\t~"(($6/div)*100)"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10; if($1 ~/00:00/) print $0;if($0 == "") instances++}' $1
else
echo -e "\tERROR: -h only functional with mem"
exit
fi
fi
if [ $5 == '-s' ]; then
awk 'BEGIN {instances = 0; max = '"$4"'; min = '"$3"'} /'"$2"'/,/^$/ {if(instances < max && instances >= min) {if($0~/'"$2"'/ || $2~/all/) print $0}; if($0 == "") instances++}' $1
else
awk 'BEGIN {instances = 0; max = '"$4"'; min = '"$3"'} /'"$2"'/,/^$/ {if(instances < max && instances >= min) print $0; if($0 == "") instances++}' $1
fi