网站首页 > 博客文章 正文
学习Linux命令,我们需要有一台Linux服务器。有了服务器,就想看看它的性能怎样。翻出自己较早前写的一个脚本,一键查看系统大部分参数。在这个基础上,对命令进行了注释,方便。
This is an old script used to display the hardware information of a server. Generated infos include hostname, IP, Bits-of-OS, CPU, memory, disk .etc.
#!/bin/bash
# -*- coding: UTF-8 -*-
#屏幕输出
echo "This lists the information of this computer."
#输出空行
echo
##tput setaf [0-7] –使用ANSI转义设置前景色
#Color Code for tput:
#0 – Black
#1 – Red
#2 – Green
#3 – Yellow
#4 – Blue
#5 – Magenta
#6 – Cyan
#7 – White
##tput sgr0 – Turn off all attributes
##`hostname` 返回主机名
#`/sbin/ifconfig` ifconfig是linux中用于显示或配置网络设备(网络接口卡)的命令
# sed -n '2p' 显示文件的第2行
# cut是一个选取命令,就是将一段数据经过分析,取出我们想要的内容
# -d :自定义分隔符,默认为制表符。-f :与-d一起使用,指定显示哪个区域。
echo "Hostname is $(tput setaf 3)`hostname`$(tput sgr0),\
Ip address is $(tput setaf 3)\
`/sbin/ifconfig | sed -n '2p' | cut -d ':' -f 2 | cut -d ' ' -f 1`.
$(tput sgr0)"
#---------------------------------------------------------------------------
#uname -a :显示系统名、节点名称、操作系统的发行版号、操作系统版本、运行系统的机器 ID 号。
# Linux ehbio 2.6.32-642.4.2.el6.x86_64 #1 SMP Tue Aug 23 19:58:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
#
nuclear=`uname -a | cut -d ' ' -f 3`
bitInfo=`uname -a | cut -d ' ' -f 12`
# if语句,判断系统是64位还是32位
if test $bitInfo == "x86_64"; then
bit=64
else
bit=32
fi
#tput bold – Set bold mode
#head -n 打印每个文件的前n行,而不是打印默认的前10行
# /etc/issue 查看系统登陆信息、发行版本信息
#
echo "The $(tput bold)${bit}$(tput sgr0) bt operating \
system is $(tput bold) `head -n 1 /etc/issue`\
$(tput sgr0), Nuclear info is $(tput setaf 1)\
${nuclear}$(tput sgr0)."
#打印空行
echo
# `sed -n '5p' /proc/cpuinfo 得到如下结果model name : Intel(R) Xeon(R) CPU G7-4809 v2 @ 4.90GHz
#sed 's/[ ] */ /g'貌似什么也没做啊,这是不对的,这句话是把多个相连空格变为单个空格
echo "The CPU is$(tput setaf 4)`sed -n '5p' /proc/cpuinfo \
| cut -d ':' -f 2 | sed 's/[ ] */ /g'`$(tput sgr0)."
echo
echo "There are $(tput setaf 5)\
`cat /proc/cpuinfo | grep "physical id" | sort | uniq \
| wc -l`$(tput sgr0) physical cpu, \
each physical \
cpu has$(tput setaf 5)`sed -n '12p' /proc/cpuinfo | \
cut -d ':' -f 2`$(tput sgr0) cores,\
$(tput setaf 5)`sed -n '10p' /proc/cpuinfo | \
cut -d ':' -f 2`$(tput sgr0) threads."
echo
echo "There are $(tput setaf 5)\
`cat /proc/cpuinfo | grep "cpu cores" | wc -l`$(tput sgr0) logical cpu."
# sed元字符集 ^ 匹配行开始,如:/^sed/匹配所有以sed开头的行。* 匹配0个或多个字符,如:/ *sed/匹配所有模板是一个或多个空格后紧跟sed的行。
#sed 's/^ *//g' 删除开头的空格
#bc命令是一种支持任意精度的交互执行的计算器语言 bc -l 定义使用的标准数学库
mem=`head -n 1 /proc/meminfo | cut -d ':' -f 2 | sed 's/^ *//g' | cut -d ' ' -f 1`
memInM=$(echo "$mem/1024/1024" | bc -l)
echo
echo "The memory of this server is $(tput setaf 5)${memInM}$(tput sgr0)G."
echo
echo "The disk information is :"
#linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。
#-h 方便阅读方式显示
echo "`df -h`"
- 上一篇: Linux常用命令大全
- 下一篇: Linux入门常用必会60个命令实例详解(一)
猜你喜欢
- 2024-11-21 超好用的UnixLinux 命令技巧 大神为你详细解读
- 2024-11-21 linux命令清单
- 2024-11-21 软件性能测试相关的Linux命令总结
- 2024-11-21 Linux中查看磁盘大小、文件大小
- 2024-11-21 【Linux】查看信息的常用命令CPU、内存、进程、网口、磁盘、硬件
- 2024-11-21 5个比较实用的Linux命令,工作中100%你在用
- 2024-11-21 Linux入门常用必会60个命令实例详解(一)
- 2024-11-21 Linux常用命令大全
- 2024-11-21 Linux环境中几个常用运维命令的使用指引
- 2024-11-21 Linux的常用命令就是记不住,怎么办?于是推出了这套教程
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)