将 sar 命令结果输出到 csv 文件 [英] Output sar command results to a csv file

查看:29
本文介绍了将 sar 命令结果输出到 csv 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 shell 编程比较陌生,想知道是否有一种简单的方法可以将 sar 命令的结果输出到 csv 文件.使用 sar >file1.csv 可以完成这项工作,但格式不正确.所有数据都存在于一列中.我试过这个,但更糟

I'm relatively new to shell programming and would like to know if there is a simple way to output the results of the sar command to a csv file. Using sar > file1.csv does the job, but it is not properly formatted. All the data is present in one column. I tried this, but it was worse

sar -d -u -w 1 1 | grep -v Average | grep -v Linux | tr -s ' ' ',' | tr -d '\n' > file1.csv

谁能给我正确的脚本来将 sar 命令的输出存储在 csv 文件中.帮助将不胜感激.

Can anyone give me the right script to store the output of the sar command in a csv file. Help will be appreciated.

推荐答案

sar -d -u -w 1 1 | grep -v Average | grep -v Linux |awk '{if ($0 ~ /[0-9]/) { print $1","$2","$4","$5","$6; }  }'



22:14:04,CPU,%nice,%system,%iowait
22:14:05,all,0.00,8.53,0.00
22:14:04,proc/s,,,
22:14:05,0.00,,,
22:14:04,DEV,rd_sec/s,wr_sec/s,avgrq-sz
22:14:05,dev8-0,0.00,0.00,0.00

上面的输出享受

这篇关于将 sar 命令结果输出到 csv 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆