1

I am running following command and getting following output which I am saving into file.

sysstat/iostat -mdt sda1 1 >> /tmp/disk.out &

Outout is following

Linux 3.16.0-25-generic (bscpower8n2)   09/25/2016  _ppc64le_   (192 CPU)

09/25/2016 08:12:01 PM
Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sda1              0.00         0.00         0.00          1          0

09/25/2016 08:12:02 PM
Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sda1              0.00         0.00         0.00          0          0

09/25/2016 08:12:03 PM
Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sda1              0.00         0.00         0.00          0          0

09/25/2016 08:12:04 PM
Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sda1              0.00         0.00         0.00          0          0

09/25/2016 08:12:05 PM
Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sda1              0.00         0.00         0.00          0          0

09/25/2016 08:12:06 PM
Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sda1              0.00         0.00         0.00          0          0

But I want to save it without header and datetime also in same row. Could anyone let me know how to achieve this? e.g

09/25/2016 08:12:01 PM sda1 0.00 0.00 0.00 1 0
09/25/2016 08:12:02 PM sda1 0.00 0.00 0.00 0 0
muru
  • 4,723
  • 1
  • 34
  • 78
David
  • 481
  • 5
  • 14

2 Answers2

0

I have following script written and though it may need improvement, it worked.

#!/bin/bash
while true; 
do  
    iostat -mdt sda1 1 1 | sed -n -e '1d' -e '/^Device:/d' -e '/^$/d' -e 'p' |sed -e 'N;s/\n/ /'
    sleep 1
done;
muru
  • 4,723
  • 1
  • 34
  • 78
jpeiper
  • 1
  • 1
0

@jpeiper: this loop doesn't work well for me as it gives the same average value (over a longer period) all the time. Only if you let iostat show several values in the continuous mode it will show you shorttime interval values. You can use grep but it will not push the info to the logfile until the grep buffer is full, and you cannot add extra information to/between the output lines (which you can with a loop) I'm still looking for a better solution.

Phillip
  • 11
  • 2
  • @Shuja The best I can think of now, for a single disk, is showing 2 values quickly after each other, and picking only the second value. However it will probably mean that you will miss the iostat data for half of the time/seconds.
    `iostat -1 -c 2 -d sdb | tail -n 2 | head -n 1`
    In your `do ... while` loop you can add the date etc.
    – Phillip Mar 23 '22 at 16:37
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 24 '22 at 12:56
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/31359230) – PM 77-1 Mar 25 '22 at 21:25