1753784 Members
6999 Online
108799 Solutions
New Discussion юеВ

Re: Script to add time

 
SOLVED
Go to solution
Ninad_1
Honored Contributor

Script to add time

Hi,

Has anyone developed a script or can give me a clue on how to go about for the following.
I have collected iostat output running with interval of 600 secs and for a count of 144 - thus it runs for 24 hrs, the output is redirected to a file. Now If I want to insert the time in the stats file , knowing the start time and the interval - how can I do this ? e.g. I start to collect iostat as
iostat 600 144 > iostat.out
at say 10:00 on 210406 then I want to insert the date:time for each entry in the iostat output. The output for a particular interval is seperated by blank lines (you can see running the command for small interval and count to see the output file)
so if output is like

c100t6d0 113 12.9 1.0
c100t5d0 21 4.1 1.0

c100t6d0 120 17.6 1.0
c100t5d0 43 5.5 1.0
.
.
and so on. and I want to have output like

210406#10:00 c100t6d0 113 12.9 1.0
210406#10:00 c100t5d0 21 4.1 1.0

210406#10:10 c100t6d0 120 17.6 1.0
210406#10:10 c100t5d0 43 5.5 1.0
.
.
and so on. Also the date change should be taken into account as the stats are for 24 hrs or more.
Thanks a lot,
Ninad

8 REPLIES 8
Geoff Wild
Honored Contributor

Re: Script to add time

What about doing iostat for a short time period - multiple times?

IOSTAT=`iostat 5 5`
echo "`date` $IOSTAT" >> iostat.out

or something like that...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Ninad_1
Honored Contributor

Re: Script to add time

Geoff,

The problem with your suggestion is that each time the iostat runs it first shows the stats till that point in time - or something like that as the first output and then it shows the actual stats collected for the mentioned interval - this is one problem. The second problem is that if I get the iostat output in IOSTAT variable then there are no new line characters seperating the outputs for each disk.
Can you suggest some alternative.

Thanks,
Ninad
Tim Nelson
Honored Contributor

Re: Script to add time

Something as simple as the following gets you almost all the way there except the lines for multiple disk do not have the time. Maybe this will give you some better idea.

sar -d 1 1|awk 'NR > 4 {print "'"`date +%d%m%y`"'#"$0}'

output looks like this

210406#09:00:18 c8t0d0 6.00 0.50 4 24 1.86 19.72
210406# c19t0d0 2.00 0.50 2 16 0.73 16.09

Ninad_1
Honored Contributor

Re: Script to add time

Tim,

Thats a nice one, but I want to use iostat as it gives the disk stats for all disks, where as sar gives stats for the most used disks - Please correct me if I am wrong.

Thanks,
Ninad
Steve Steel
Honored Contributor
Solution

Re: Script to add time

Hi

iostat 6 1|while read line
do
echo $(date|cut -f1-4 -d" ")" : ""$line"
done

If you like the format play with it

by putting 600 144

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Peter Nikitka
Honored Contributor

Re: Script to add time

Hi,

with GNU-awk it's a oneliner, a nearly identical perl solution should be easy.
- I skip empty lines.
- Note, that depending an your header lines of iostat, you have to change for padding.
- Your date format consists of 10chars - thats
the number of blanks in the first print statement.

iostat ... | gawk -v head=2 'NR<=head {print " ",$0}; NR>head && NF {print strftime("%d%m%y#%H:%M"),$0}'

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Tim Nelson
Honored Contributor

Re: Script to add time

iostat makes it easier.

iostat|awk 'NR > 3 {print "'"`date +%d%m%y#%T `"'"$0}'

210406#09:40:15 c8t0d0 0 0.0 1.0
210406#09:40:15 c19t0d0 0 0.0 1.0
210406#09:40:15 c19t3d0 0 0.0 1.0
210406#09:40:15 c8t3d0 0 0.0 1.0
210406#09:40:15 c8t1d0 0 0.0 1.0
210406#09:40:15 c8t2d0 0 0.0 1.0
210406#09:40:15 c19t1d0 0 0.0 1.0
210406#09:40:15 c19t2d0 0 0.0 1.0
Ninad_1
Honored Contributor

Re: Script to add time

Steve,Tim,

Thats exactly what I wanted.
Thanks a lot for the wonderful help.

Peter,
Unfortunately I dont have gawk currently. But will use your suggestion some time latter.

Thanks,
Ninad