Bash get-hardware 脚本输出到 .csv 文件

Bash get-hardware script output to .csv file

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

https://pastebin.com/5Um4Bir6

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

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 文件。 并且输出应该像 header 那样有 SYSTEM、CPU、MEMORY 等。各个列应该有像 lshwethtoolnvidia-smi,等等

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

{
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