Shell script to read the system running state

Source: Internet
Author: User

Recently in the study shell, eldest brother let write a read system configuration information script as practice and work acceptance, I wrote such a script, read the operating system, kernel, network card, CPU, memory, disk and other information, the purpose is to see the person at a glance can see the configuration of this machine and the current state of operation:

#!/bin/bash#get System Infomation (sys_time=$ (date + "%y-%m-%d%k:%m:%s") #os_version =$ (lsb_release-a | sed-n '/ Description/p ' | Awk-f ' [:] ' {print $} ' | Sed ' s/^[[:space:]]*//') os_version=$ (cat/etc/issue | grep Linux) kernel_release=$ (uname-r) netcard_num=$ (ifconfig-a | grep ETH | WC-L) echo "[Public_info]" echo-e "sys_time= $sys _time\t# system Time" ECHO-E "os_version= $os _version\t# Operating system version" ECHO-E " kernel-release= $kernel _release\t# kernel version "######## #NETCADE infomation######### #echo echo" [Netcard_info] "echo" netcard _num= $netcard _num "echo" #网卡名字 | ip| mac| Network Card Driver | Network card Speed | Network card send traffic (bytes) | Network card receive traffic (bytes) | nic Total traffic (bytes) "for ((n=0;n< $netcard _num;n++)) doreceive_byte=$ (CAT/ Proc/net/dev | grep eth$n | awk ' {print$2} ') send_byte=$ (Cat/proc/net/dev | grep eth$n | awk ' {print$10} ') echo "netcard_$ ((n+1)) =eth$n|$ (ifconfig eth$n | grep "inet addr" | awk ' {print$2} ' | Awk-f ' [:] ' {print$2} ') |$ (ifconfig-a | grep eth$n | awk ' {print$5} ') |$ (ethtool eth$n | grep speed | awk ' {print$2} ' | se d ' s/^[[:space:]]*//') |${receive_byte}|${send_bytei}|$ (($Receive _byte + $Send _byte)) "done######### #CPU infomation############# #cpu_phical_count =$ ( Cat/proc/cpuinfo | grep "Physical ID" | Sort | Uniq | wc-l) cpu_model=$ (cat/proc/cpuinfo | grep "model name" | uniq | awk-f ' [:] ' {print$2} ') cpu_core_num=$ (cat/proc/cpuinfo | grep Cores | Uniq | Awk-f ' [:] ' {print $} ' | Sed ' s/^[[:space:]]*//') cpu_process_num=$ (cat/proc/cpuinfo | grep process | wc-l) cpu_frequency=$ (Cat/proc/cpuinfo | grep Mhz|uniq | Awk-f ' [:] ' {print $} ' | Sed ' s/^[[:space:]]*//') cache_size=$ (Cat/proc/cpuinfo | grep "Cache size" | uniq | awk-f ' [:] ' {print$2} ') cpu_idle=$ (MPs Tat | grep all | awk ' {print$11} ') cpu_used=$ (mpstat | grep all | awk ' {print$3} ') Echoecho "[Cpu_info]" echo-e "cpu_model= $cpu _model\t# CPU model "ECHO-E" cpu_core_num= $cpu _core_num\t#cpu number of cores "ECHO-E" cpu_phical_count= $cpu _phical_count\t#cpu number "ECHO-E" cpu_ frequendy= $cpu _frequency\t# Frequency/single "ECHO-E" cache_size=${cache_size}* $cpu _process_num\t# Cache "ECHO-E" cpu_idle=${cpu_ idle}%\t# Idle Rate "echo -E "cpu_used=${cpu_used}%\t# usage" ########## #memeber info############## #echoecho "[Mem_info]" ECHO-E "mem_total=$ ( free-m | grep Mem | awk ' {print$2} ') \t# total Memory "ECHO-E" mem_used=$ (free-m | grep Buffers/cache | awk ' {print$3} ') \t# has been using "ECHO-E" mem_free=$ (free-m | grep Buffers/cache | awk ' {print$4} ') \t# can use "########## #hard info ################# #file_system_num =$ (df-ph | grep/| wc-l) Echoecho" [Hard_i NFO] "echo" file_system_num= $file _system_num "echo" #磁盘总容量 (unit m) | used capacity (in M) | available traffic (unit m) | used% (%) | mount Directory "DF-PM | grep/| awk ' {print$2 ' | $ "|" $4 "|" $ "|" $6} ' exit 0) >system_infomation.txt

The result of the operation is this:

[Public_info]
Sys_time=2014-12-18 11:42:43 #系统时间
os_version=red Hat Enterprise Linux Server release 6.4 (Santiago)#操作系统版本
kernel-release=2.6.32-358.el6.i686 #内核版本


[Netcard_info]
Netcard_num=4
#网卡名字 | ip| mac| Network Card Driver | Network card Speed | Network card send traffic (bytes) | Network card receive traffic (bytes) | Network card Total traffic (bytes)
netcard_1=eth0| | 28:51:32:04:68:31|1000mb/s|6863054| | 13709858
netcard_2=eth1| | 28:51:32:04:68:32| unknown!| 0| | 0
netcard_3=eth2| | 28:51:32:04:68:33|1000mb/s|6846296| | 13709858
netcard_4=eth3|192.168.6.193|28:51:32:04:68:34|1000mb/s|209054928| | 209117419


[Cpu_info]
Cpu_model= Intel (R) Atom (TM) CPU D525 @ 1.80GHz #cpu型号
cpu_core_num=2 #cpu核数
Cpu_phical_count=1 #cpu个数
cpu_frequendy=1800.000 #主频/Single
Cache_size= kb*4 #缓存
cpu_idle=99.60% #空闲率
cpu_used=0.06% #使用率


[Mem_info]
mem_total=993 #总内存
mem_used=566 #已使用
mem_free=427 #可使用


[Hard_info]
File_system_num=4
#磁盘总容量 (unit m) | used capacity (in M) | available flow (in M) | used percent (%) | Mount Directory
162650|17438|136950|12%|/
497|0|497|0%|/dev/shm
291|31|245|12%|/boot
78745|815|73931|2%|/home

Shell script to read the system running state

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.