【问题标题】:How to remove repeated header from the output of iostat linux command如何从 iostat linux 命令的输出中删除重复的标头
【发布时间】:2017-02-03 12:36:16
【问题描述】:

我正在运行以下命令并获得以下输出,并将其保存到文件中。

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

输出如下

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

但我想将它保存在同一行中,而不需要标题和日期时间。谁能让我知道如何实现这一目标? 例如

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

【问题讨论】:

    标签: iostat


    【解决方案1】:

    我编写了以下脚本,虽然它可能需要改进,但它确实有效。

    #!/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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-09
      • 2021-03-01
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-04
      • 2016-02-15
      相关资源
      最近更新 更多