Please, urgent help in this script

Please, urgent help in this script

am 15.09.2007 16:46:26 von apogeusistemas

Hi:

I need get a sar -d output and format this output:

solaris> sar -d

SunOS Solaris 10 5.10 Generic_118855-33 i86pc 09/14/2007

01:34:54 device %busy avque r+w/s blks/s
avwait avserv

01:34:54 cmdk0 0 0.0
1 3 2.4 3.7
fd0 0 0.0
1 3 2.4 3.7
nfs1 0 0.0
1 3 2.4 3.7
sd16 0 0.0
1 3 2.4 3.7

01:39:54 cmdk0 0 0.0
0 3 2.4 3.7
fd0 0 0.0
0 3 2.4 3.7
nfs1 0 0.0
0 3 2.4 3.7
sd16 0 0.0
0 3 2.4 3.7

and get this output:

solaris> sar -d | ./script

01:34:54 cmdk0 0 0.0
1 3 2.4 3.7
01:34:54 fd0 0 0.0
1 3 2.4 3.7
01:34:54 nfs1 0 0.0
1 3 2.4 3.7
01:34:54 sd16 0 0.0
1 3 2.4 3.7

01:39:54 cmdk0 0 0.0
0 3 2.4 3.7
01:39:54 fd0 0 0.0
0 3 2.4 3.7
01:39:54 nfs1 0 0.0
0 3 2.4 3.7
01:39:54 sd16 0 0.0
0 3 2.4 3.7

I made this script below trying to make this task, but it does'nt work
like I desire:

solaris> cat script
sar -d | while read a b c d e f g h
do
pp=`echo $a | cut -c3-3`
if [[ $pp == ":" ]]
then
hour=$a
echo "$a $b $c $d $e $f $g $h"
while read i j k l m n o
do
echo "$hour $i $j $k $l $m $n $o"
done
fi
done


Can you help me changing this script to make it workable ?
This is a task to apply in my job.
Thank you
(maybe have an awk best solution for this case, but I'm learnig
scripting yet)

Re: Please, urgent help in this script

am 15.09.2007 17:05:23 von Janis Papanagnou

apogeusistemas@gmail.com wrote:
> Hi:
>
> I need get a sar -d output and format this output:
>
> solaris> sar -d
>
> SunOS Solaris 10 5.10 Generic_118855-33 i86pc 09/14/2007
>
> 01:34:54 device %busy avque r+w/s blks/s
> avwait avserv
>
> 01:34:54 cmdk0 0 0.0
> 1 3 2.4 3.7
> fd0 0 0.0
> 1 3 2.4 3.7
> nfs1 0 0.0
> 1 3 2.4 3.7
> sd16 0 0.0
> 1 3 2.4 3.7
>
> 01:39:54 cmdk0 0 0.0
> 0 3 2.4 3.7
> fd0 0 0.0
> 0 3 2.4 3.7
> nfs1 0 0.0
> 0 3 2.4 3.7
> sd16 0 0.0
> 0 3 2.4 3.7
>
> and get this output:
>
> solaris> sar -d | ./script
>
> 01:34:54 cmdk0 0 0.0
> 1 3 2.4 3.7
> 01:34:54 fd0 0 0.0
> 1 3 2.4 3.7
> 01:34:54 nfs1 0 0.0
> 1 3 2.4 3.7
> 01:34:54 sd16 0 0.0
> 1 3 2.4 3.7
>
> 01:39:54 cmdk0 0 0.0
> 0 3 2.4 3.7
> 01:39:54 fd0 0 0.0
> 0 3 2.4 3.7
> 01:39:54 nfs1 0 0.0
> 0 3 2.4 3.7
> 01:39:54 sd16 0 0.0
> 0 3 2.4 3.7
>
> I made this script below trying to make this task, but it does'nt work
> like I desire:
>
> solaris> cat script
> sar -d | while read a b c d e f g h
> do
> pp=`echo $a | cut -c3-3`
> if [[ $pp == ":" ]]
> then
> hour=$a
> echo "$a $b $c $d $e $f $g $h"
> while read i j k l m n o
> do
> echo "$hour $i $j $k $l $m $n $o"
> done
> fi
> done
>
>
> Can you help me changing this script to make it workable ?

It would be easier to make use of Ed's or mine awk program that we
suggested yesterday to you. E.g., changing my version

sar -d | head | awk -v d=$(date +%m/%d/%y) '{print d,t,$0}
NR==1{t=$1}'

from the previous requirement to the new one would yield something
like

sar -d | head | awk -v d=$(date +%m/%d/%y) '{print d,t,$0}
$1~/^[0-9][0-9]:/{t=$1}'

In other words just change the condition where to find the time data.

I don't know why you now omitted the date field that you asked for
yesterday; anyway, without the date processing it's yet simpler

sar -d | head | awk '{print t,$0} $1~/^[0-9][0-9]:/{t=$1}'

(All programs untested.)

Janis


> This is a task to apply in my job.
> Thank you
> (maybe have an awk best solution for this case, but I'm learnig
> scripting yet)
>

Re: Please, urgent help in this script

am 15.09.2007 17:37:41 von apogeusistemas

On 15 set, 12:05, Janis Papanagnou
wrote:
> apogeusiste...@gmail.com wrote:
> > Hi:
>
> > I need get a sar -d output and format this output:
>
> > solaris> sar -d
>
> > SunOS Solaris 10 5.10 Generic_118855-33 i86pc 09/14/2007
>
> > 01:34:54 device %busy avque r+w/s blks/s
> > avwait avserv
>
> > 01:34:54 cmdk0 0 0.0
> > 1 3 2.4 3.7
> > fd0 0 0.0
> > 1 3 2.4 3.7
> > nfs1 0 0.0
> > 1 3 2.4 3.7
> > sd16 0 0.0
> > 1 3 2.4 3.7
>
> > 01:39:54 cmdk0 0 0.0
> > 0 3 2.4 3.7
> > fd0 0 0.0
> > 0 3 2.4 3.7
> > nfs1 0 0.0
> > 0 3 2.4 3.7
> > sd16 0 0.0
> > 0 3 2.4 3.7
>
> > and get this output:
>
> > solaris> sar -d | ./script
>
> > 01:34:54 cmdk0 0 0.0
> > 1 3 2.4 3.7
> > 01:34:54 fd0 0 0.0
> > 1 3 2.4 3.7
> > 01:34:54 nfs1 0 0.0
> > 1 3 2.4 3.7
> > 01:34:54 sd16 0 0.0
> > 1 3 2.4 3.7
>
> > 01:39:54 cmdk0 0 0.0
> > 0 3 2.4 3.7
> > 01:39:54 fd0 0 0.0
> > 0 3 2.4 3.7
> > 01:39:54 nfs1 0 0.0
> > 0 3 2.4 3.7
> > 01:39:54 sd16 0 0.0
> > 0 3 2.4 3.7
>
> > I made this script below trying to make this task, but it does'nt work
> > like I desire:
>
> > solaris> cat script
> > sar -d | while read a b c d e f g h
> > do
> > pp=`echo $a | cut -c3-3`
> > if [[ $pp == ":" ]]
> > then
> > hour=$a
> > echo "$a $b $c $d $e $f $g $h"
> > while read i j k l m n o
> > do
> > echo "$hour $i $j $k $l $m $n $o"
> > done
> > fi
> > done
>
> > Can you help me changing this script to make it workable ?
>
> It would be easier to make use of Ed's or mine awk program that we
> suggested yesterday to you. E.g., changing my version
>
> sar -d | head | awk -v d=$(date +%m/%d/%y) '{print d,t,$0}
> NR==1{t=$1}'
>
> from the previous requirement to the new one would yield something
> like
>
> sar -d | head | awk -v d=$(date +%m/%d/%y) '{print d,t,$0}
> $1~/^[0-9][0-9]:/{t=$1}'
>
> In other words just change the condition where to find the time data.
>
> I don't know why you now omitted the date field that you asked for
> yesterday; anyway, without the date processing it's yet simpler
>
> sar -d | head | awk '{print t,$0} $1~/^[0-9][0-9]:/{t=$1}'
>
> (All programs untested.)
>
> Janis
>
>
>
> > This is a task to apply in my job.
> > Thank you
> > (maybe have an awk best solution for this case, but I'm learnig
> > scripting yet)- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -- Ocultar texto entre aspas -
>
> - Mostrar texto entre aspas -

This code is putting 2 hour field, like bellow:

12:05:00 12:10:00 cmdk0 0 0.0 0 0 0.2 2.0
12:10:00 fd0 0 0.0 0 0 0.0 0.0
12:10:00 nfs1 0 0.0 0 0 0.0 0.0
12:10:00 sd16 0 0.0 0 0 0.0 0.0

Re: Please, urgent help in this script

am 15.09.2007 23:52:56 von Janis Papanagnou

apogeusistemas@gmail.com wrote:
> On 15 set, 12:05, Janis Papanagnou
> wrote:
>
>>apogeusiste...@gmail.com wrote:
>>
>>>Hi:
>>
>>>I need get a sar -d output and format this output:
>>
>>>solaris> sar -d
>>
>>>SunOS Solaris 10 5.10 Generic_118855-33 i86pc 09/14/2007
>>
>>>01:34:54 device %busy avque r+w/s blks/s
>>>avwait avserv
>>
>>>01:34:54 cmdk0 0 0.0
>>>1 3 2.4 3.7
>>> fd0 0 0.0
>>>1 3 2.4 3.7
>>> nfs1 0 0.0
>>>1 3 2.4 3.7
>>> sd16 0 0.0
>>>1 3 2.4 3.7
>>
>>>01:39:54 cmdk0 0 0.0
>>>0 3 2.4 3.7
>>> fd0 0 0.0
>>>0 3 2.4 3.7
>>> nfs1 0 0.0
>>>0 3 2.4 3.7
>>> sd16 0 0.0
>>>0 3 2.4 3.7
>>
>>>and get this output:
>>
>>>solaris> sar -d | ./script
>>
>>>01:34:54 cmdk0 0 0.0
>>>1 3 2.4 3.7
>>>01:34:54 fd0 0 0.0
>>>1 3 2.4 3.7
>>>01:34:54 nfs1 0 0.0
>>>1 3 2.4 3.7
>>>01:34:54 sd16 0 0.0
>>>1 3 2.4 3.7
>>
>>>01:39:54 cmdk0 0 0.0
>>>0 3 2.4 3.7
>>>01:39:54 fd0 0 0.0
>>>0 3 2.4 3.7
>>>01:39:54 nfs1 0 0.0
>>>0 3 2.4 3.7
>>>01:39:54 sd16 0 0.0
>>>0 3 2.4 3.7
>>
>>>I made this script below trying to make this task, but it does'nt work
>>>like I desire:
>>
>>>solaris> cat script
>>>sar -d | while read a b c d e f g h
>>>do
>>>pp=`echo $a | cut -c3-3`
>>>if [[ $pp == ":" ]]
>>>then
>>>hour=$a
>>> echo "$a $b $c $d $e $f $g $h"
>>> while read i j k l m n o
>>> do
>>> echo "$hour $i $j $k $l $m $n $o"
>>> done
>>>fi
>>>done
>>
>>>Can you help me changing this script to make it workable ?
>>
>>It would be easier to make use of Ed's or mine awk program that we
>>suggested yesterday to you. E.g., changing my version
>>
>> sar -d | head | awk -v d=$(date +%m/%d/%y) '{print d,t,$0}
>> NR==1{t=$1}'
>>
>>from the previous requirement to the new one would yield something
>>like
>>
>> sar -d | head | awk -v d=$(date +%m/%d/%y) '{print d,t,$0}
>> $1~/^[0-9][0-9]:/{t=$1}'
>>
>>In other words just change the condition where to find the time data.
>>
>>I don't know why you now omitted the date field that you asked for
>>yesterday; anyway, without the date processing it's yet simpler
>>
>> sar -d | head | awk '{print t,$0} $1~/^[0-9][0-9]:/{t=$1}'
>>
>>(All programs untested.)
>>
>>Janis
>>
>>
>>
>>
>>>This is a task to apply in my job.
>>>Thank you
>>>(maybe have an awk best solution for this case, but I'm learnig
>>>scripting yet)- Ocultar texto entre aspas -
>>
>>- Mostrar texto entre aspas -- Ocultar texto entre aspas -
>>
>>- Mostrar texto entre aspas -
>
>
> This code is putting 2 hour field, like bellow:

Not in the first one but in subsequent date fields, yes.

>
> 12:05:00 12:10:00 cmdk0 0 0.0 0 0 0.2 2.0
> 12:10:00 fd0 0 0.0 0 0 0.0 0.0
> 12:10:00 nfs1 0 0.0 0 0 0.0 0.0
> 12:10:00 sd16 0 0.0 0 0 0.0 0.0
>
>

How to handle empty lines?

awk '$1~/^[0-9][0-9]:/{t=$1;$1=""} NF{print t,$0} !NF{print""}'


Janis

Re: Please, urgent help in this script

am 16.09.2007 09:31:48 von John L

wrote in message news:1189867586.526934.73600@y42g2000hsy.googlegroups.com...
> Hi:
>
> I need get a sar -d output and format this output:
>
> solaris> sar -d
>
> SunOS Solaris 10 5.10 Generic_118855-33 i86pc 09/14/2007
>
> 01:34:54 device %busy avque r+w/s blks/s
> avwait avserv
>
> 01:34:54 cmdk0 0 0.0
> 1 3 2.4 3.7
> fd0 0 0.0
> 1 3 2.4 3.7
> nfs1 0 0.0
> 1 3 2.4 3.7
> sd16 0 0.0
> 1 3 2.4 3.7
>
> 01:39:54 cmdk0 0 0.0
> 0 3 2.4 3.7
> fd0 0 0.0
> 0 3 2.4 3.7
> nfs1 0 0.0
> 0 3 2.4 3.7
> sd16 0 0.0
> 0 3 2.4 3.7
>
> and get this output:
>
> solaris> sar -d | ./script
>
> 01:34:54 cmdk0 0 0.0
> 1 3 2.4 3.7
> 01:34:54 fd0 0 0.0
> 1 3 2.4 3.7

I think the problem is that the wrapped lines are confusing people.
(Btw, script is a bad name because there is already a command
called script.)

Here is an awk script that will do what (I think) you want.
Put it in a file called (say) sarformat: sar -d |nawk -f sarformat

NF == 0 { print; next }
$NF ~ /[0-9]\/[0-9][0-9]/ { date = $NF; print; next }
$1 ~ /:/ || $1 == "Average" {
timestamp = sprintf("%-8s", $1); print date, $0; next
}
{
row = $0
sub(" ", timestamp, row)
print date, row
}

--
John.