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

[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

 

posted @   小糊涂90  阅读(161)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示