首页 > 其他分享 >显示服务器配置信息

显示服务器配置信息

时间:2023-05-07 23:34:10浏览次数:47  
标签:setaf tput 配置 sgr0 信息 echo cut sed 服务器



公众微信号:http://blog.genesino.com
学习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`"


标签:setaf,tput,配置,sgr0,信息,echo,cut,sed,服务器
From: https://blog.51cto.com/u_16077014/6252738

相关文章

  • java基于springboot+vue非前后端分离的学生成绩管理系统、学生信息管理系统,附源码+数
    1、项目介绍java基于springboot+vue非前后端分离的学生成绩管理系统、学生信息管理系统。本文首先介绍了学生成绩管理的技术发展背景与发展现状,然后遵循软件常规开发流程,首先针对系统选取适用的语言和开发平台,根据需求分析制定模块并设计数据库结构,再根据系统总体功能模块的设计......
  • Prometheus系列---【Prometheus使用node-exporter监控服务器运行情况】
    Prometheus使用node-exporter监控服务器运行情况作用node_exporter是一个用于收集主机指标的Prometheusexporter。1.下载node-exporter下载地址:https://github.com/prometheus/prometheus/releases2.上传到服务器并解压tar-zxvfxxx.tar.gz3.启动node-exporter#--w......
  • windows提权-系统错误配置提权
    windows提权-系统错误配置提权目录windows提权-系统错误配置提权一、错误配置提权介绍二、TustedServicePaths提权原理三、PATH环境变量提权四、不安全的服务提权五、不安全注册表提权六、注册表键AlwaysInstall提权七、泄露敏感信息提权八、计划任务提权九、启动项提权一、错......
  • Vue.js:Vue-Router动态路由从服务器接口获取路由数据
    (目录)文档https://v3.router.vuejs.org/zh/installation.html版本号"vue":"2.6.10","vue-router":"3.6.5",有几种方式实现动态路由:前端配置完整路由,通过接口返回的数据判断是否可显示,是否可访问前端配置部分路由,由后端接口返回的数据生成新路由抛开路由的思维,是否......
  • Hibernate4之二级缓存配置
    缓存:缓存是什么,解决什么问题? 位于速度相差较大的两种硬件/软件之间的,用于协调两者数据传输速度差异的结构,均可称之为缓存Cache。缓存目的:让数据更接近于应用程序,协调速度不匹配,使访问速度更快。 缓存的范围分为3类: 1.事务范围(单Session即一级缓存)   事务范围......
  • 12 KVM虚拟机配置-配置虚拟设备(网络设备)
    12KVM虚拟机配置-配置虚拟设备(网络设备)12.1概述XML配置文件可以配置虚拟网络设备,包括ethernet模式、bridge模式、vhostuser模式等,本节介绍虚拟网卡设备的配置方法。12.2元素介绍XML配置文件中使用元素“interface”,其属性“type”表示虚拟网卡的模式,可选的值有“ethernet......
  • 入门6-Pytest全局配置文件
    通过全局配置pytest.ini文件执行()//会自动加载此文件注意:一般放在项目根目录下,并且名字必须为pytest.ini编码格式为ANSI,有中文需要GBS1218pytest.ini可以改变默认测试用例规则不管main还是命令方式都会自动加载此配置文件内容举例:[pytest]//代表配置文件Addopts==“-......
  • 遇到的问题:nacos配置管理,无法获取到nacos中的配置内容
    nacos中的配置: bootstrap.yml文件:    1spring:2application:3name:userservice4profiles:5active:dev#环境6cloud:7nacos:8server-addr:localhost:8848#nacos地址9config:10file-extensio......
  • Java Bean介绍与配置
    (一)JavaBean介绍1.javaBean的介绍在Java中,有很多class的定义都符合这样的规范:若干private实例字段;通过public方法来读写实例字段。例如:publicclassPerson{privateStringname;privateintage;publicStringgetName(){returnthis.name;}p......
  • ubuntu 中查看系统信息
     001、root@ubuntu01:~#cat/etc/issueUbuntu22.04.2LTS\n\l 002、root@ubuntu01:~#lsb_release-aNoLSBmodulesareavailable.DistributorID:UbuntuDescription:Ubuntu22.04.2LTSRelease:22.04Codename:jammy 003、root......