gpt4 book ai didi

linux - bash 获取硬件脚本输出到 .csv 文件

转载 作者:行者123 更新时间:2023-12-04 18:44:16 25 4
gpt4 key购买 nike

我正在使用以下脚本来获取服务器硬件信息:

https://pastebin.com/5Um4Bir6

下面的代码只是其中的一部分(正如 StackOverflow 推荐的那样)

echo
echo -e "+++++++++++++++++++ \e[1;34m SYSTEM \e[0m+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
lshw -c system -short |sed 's/ \{1,\}/ /g'| cut -d' ' -f2-100 |grep -v "=" |grep -v Desc |grep -v PNP |sed 's/system //g'
echo
echo -e "+++++++++++++++++++ \e[1;34m CPU \e[0m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
lshw -c processor -short |grep -v "=" |grep -v Desc |sed 's/ \{1,\}/ /g'| cut -d' ' -f2-100 |sed 's/processor //g'
echo
echo -e "+++++++++++++++++++ \e[1;34m MEMORY \e[0m ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
lshw -c memory -short |grep -v "=" |grep -v Desc |grep -v empty |grep -v cache |sed 's/ \{1,\}/ /g'| cut -d' ' -f2-100 |sed 's/memory //g' |grep DIMM

我在 Ubuntu 18.04.03 和 CentOS 7 机器上使用此脚本,我需要帮助才能将输出转换为 .csv 文件。
并且输出应该像具有 SYSTEM、CPU、MEMORY 等的标题。相应的列应该具有命令的输出,如 lshw , ethtool , nvidia-smi , ETC。

最佳答案

尝试通过大括号 { } 使用命令分组和 >>重定向。

{
echo
echo -e "+++++++++++++++++++ \e[1;34m SYSTEM \e[0m+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
lshw -c system -short |sed 's/ \{1,\}/ /g'| cut -d' ' -f2-100 |grep -v "=" |grep -v Desc |grep -v PNP |sed 's/system //g'
echo
echo -e "+++++++++++++++++++ \e[1;34m CPU \e[0m +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
lshw -c processor -short |grep -v "=" |grep -v Desc |sed 's/ \{1,\}/ /g'| cut -d' ' -f2-100 |sed 's/processor //g'
echo
echo -e "+++++++++++++++++++ \e[1;34m MEMORY \e[0m ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
lshw -c memory -short |grep -v "=" |grep -v Desc |grep -v empty |grep -v cache |sed 's/ \{1,\}/ /g'| cut -d' ' -f2-100 |sed 's/memory //g' |grep DIMM
} >> file.csv

关于linux - bash 获取硬件脚本输出到 .csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60829066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com