#!/bin/bash #title:统计系统信息 #author:Jelly_lyj #date:2016-08-05 #version:V0.01 #other:此脚本仅用于Linux系统的系统信息统计 #===================================================== #Fuction System_info()-->收集和输出 系统|硬件相关信息 #===================================================== System_info() { #显示系统版本号 System_version=`cat /etc/redhat-release |awk '{print $1,$2,$7}'` #内核版本 System_kernel=`uname -r` #系统物理cpu个数和各个cpu有几个核 Sytem_cpu=`cat /proc/cpuinfo | grep "physical id"|sort|uniq -c|awk '{print "CPU:"$2,$NF,"Core:"$1}'` #机器型号 System_machine_model=`dmidecode | grep "Product Name" |sed -n '1p'|sed 's/[ ]//g'` #CPU型号 System_cpu_model=`cat /proc/cpuinfo |egrep "model name"|uniq|awk '{print$4" "$5}'` #显卡型号 System__gpu_model=`lspci|grep VGA |awk '{print $5" "$6" "$7" "$8" "$9}'` echo "=============System_info===============" echo "系统使用的Linux系统版本是:$System_version" echo "系统的内核版本是:$System_kernel" echo -e "系统cpu个数与核数是: $Sytem_cpu" echo "各个硬件型号:" echo " (1)机器型号:$System_machine_model" echo " (2)CPU型号:$System_cpu_model" echo " (3)显卡型号:$System__gpu_model" echo "=============System_info===============" } #==================================== #Fuction Disk_info() 收集硬盘|分区信息 #==================================== Disk_info() { #使用/tmp/disk.txt文件来存放各个硬盘名称 [ -f /tmp/disk.txt ] if [ $? -eq 0 ] then echo -n "">/tmp/disk.txt fdisk -l |egrep "Disk /dev"|awk '{print $2}'|awk -F: '{print$1}' >/tmp/disk.txt else touch /tmp/disk.txt fdisk -l |egrep "Disk /dev"|awk '{print $2}'|awk -F: '{print$1}' >/tmp/disk.txt fi Disk_count=`fdisk -l |egrep "Disk /dev"|wc -l` echo "=============Disk_info===============" echo "本机共有$Disk_count块硬盘" while read disk do Disk_DX=`fdisk -l $disk 2>/dev/null | egrep "Disk */" |awk '{print $2$3$4}'|sed -e 's/:/=/g' -e s/,//g` Disk_FQ=`fdisk -l $disk |egrep "^/dev"|wc -l` echo " 其中$Disk_DX,有$Disk_FQ个分区" done < /tmp/disk.txt echo "=============Disk_info===============" } #==================================== #Fuction Mem_info()--->收集内存信息 #==================================== Mem_info() { #分别提取出内存的total、used、free total=`free |egrep "^Mem"|awk '{print $2}'` used=`free |egrep "^Mem"|awk '{print $3}'` free=`free |egrep "^Mem"|awk '{print $4}'` #利用bc按照单位为GB的格式输出 total_G=`echo "scale=1;$total/1000000"|bc` used_G=`echo "scale=1;$used/1000000" |bc` free_G=`echo "scale=1;$free/1000000" |bc` echo "=============Mem_info===============" echo "Mem total:$total_G G" echo "Mem used:$used_G G" echo "Mem free:$free_G G" echo "=============Mem_info===============" } #==================================== #Fuction Os_info() 收集操作系统信息 #==================================== Os_info() { #当前系统运行级别 Os_runlevel=`runlevel |awk '{print$2}'` #当前系统登录用户 Os_user=`whoami` echo "=============Os_info===============" echo "当前运行的系统级别是:$Os_runlevel" echo "当前系统登录用户:$Os_user" echo "=============Os_info===============" } #========================================= #Fuction Network_info() 收集操作系统信息 #========================================= Network_info() { #计算本机IP个数 IPGS=`ifconfig |egrep "<inet>" |wc -l` #查询本机网关地址 GW=`route -n |egrep "^0.0.0.0"|awk '{print $2}'` echo "=============Network_info===============" echo "本机IP地址有$IPGS个" ifconfig |egrep "<inet>" |awk '{print$2":"$4}'|awk -F: '{print" IP:"$2",""子网掩码:"$4}' echo "网关地址为:$GW" echo "=============Network_info===============" } #==================================== #Function-->供用户交互选择的主菜单界面 #==================================== Menu() { echo "=============欢迎使用系统信息查询功能===============" echo echo "1. 系统|硬件信息" echo echo "2. 硬盘|分区信息" echo echo "3. 内存信息" echo echo "4. 操作系统|运行信息" echo echo "5. 网络信息" echo echo "0. 退出系统" read -p " 请你输入你想查询的信息:" choice case $choice in 1) clear System_info Menu ;; 2) clear Disk_info Menu ;; 3) clear Mem_info Menu ;; 4) clear Os_info Menu ;; 5) clear Network_info Menu ;; 0) exit 0 ;; *) echo "sorry,输入错误!" Menu ;; esac } #==================================== #Function--->主函数 #==================================== Main() { Menu } #==================================== #入口 #==================================== Main;