
Hi,
I am editing an existing script which reads the output from the sar command. Right now the script just pulls one field from the output table.
Code:
queue=`/usr/bin/sar -q 1 5 |grep Average |awk '{print $3}'`
if [ $queue -ge 100 ]; then ....
The output of the sar command is this.
15:00:42 runq-sz %runocc swpq-sz %swpocc
15:00:43 2.0 1 0.0 0
15:00:44 0.0 0 0.0 0
15:00:45 0.0 0 0.0 0
Average 2.0 1 0.0 0
I need to pull another field out of here (eg. print $2) and get it into a variable for some further logic.
I cant do:
Code:
var1`/usr/bin/sar -q 1 5 |grep Average |awk '{print $3}'
var2=`/usr/bin/sar -q 1 5 |grep Average |awk '{print $2}'
Because that would product two different outputs. I know I can write this to a file and do it, but it has been suggested that this can be done more cleanly without having to write to a file.
This is only my second time coding in BASH, which I think I am going to love. Help appreciated.. Thanks