编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小

发布时间 2023-10-07 13:58:25作者: 小糊涂90
[10:03:38 root@centos8 ~]#cat  systeminfo.sh
#!/bin/bash

#================================================================
#   Copyright (C) 2021 IEucd Inc. All rights reserved.
#
#   文件名称:systeminfo.sh
#   创 建 者:TanLiang
#   创建日期:2021年09月20日
#   描   述:This is a test file
#
#================================================================

echo -e "1.主机名:\e[31m`hostname`\e[0m"
echo -e "2:ipv4地址:\e[31m`ip a |grep eth0 |grep inet |tr -s " " |cut -d" " -f3|cut -d/ -f1`\e[0m"
echo -e "3.操作系统版本:\e[31m`hostnamectl |awk -F: 'NR==7{print $2}'`\e[0m"
echo -e "4.内核版本:\e[31m`uname -r`\e[0m"
echo -e "5.cpu型号:\e[31m`lscpu|awk 'NR==13{print $0}'|cut -d: -f2|tr -s " "`\e[0m"
echo -e "6.内存大小:\e[31m`free -mh|grep Mem |tr -s " "|cut -d" " -f2`\e[0m"
echo -e "7.硬盘大小:\n\e[31m`df -h |grep sda|awk '{print $1,"\t",$2,"\t",$6}'`\e[0m"
[10:03:50 root@centos8 ~]#bash systeminfo.sh
1.主机名:centos8.magedu.org
2:ipv4地址:10.0.0.150
3.操作系统版本: CentOS Linux 8
4.内核版本:4.18.0-240.el8.x86_64
5.cpu型号: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
6.内存大小:1.9Gi
7.硬盘大小:
/dev/sda5       100G   /
/dev/sda2       50G     /date
/dev/sda1       976M   /boot