分享一個查看CentOS系統信息的腳本

最近在看《實戰Linux Shell編程與服務器管理》,一邊看一邊練習,看到sed和awk時感覺這兩個工具真是太好用了。學以致用,於是想平時想看看系統信息,總是去查命令,然後去一堆信息裏去找,不如寫個腳本來練練手,於是就有了InfoView4CentOS這個腳本。

代碼託管在Github(也是來練習使用Github的),地址:https://github.com/callmepeanut/InfoView4CentOS

採用選單的方式,可以查看ip、硬件等信息,運行效果如下:

[root@localhost InfoView4CentOS]# ./InfoView4CentOS.sh
1) HostIp                 3) SystemVersion          5) NonDefault-LoginUsers
2) HardwareInfo           4) OpenPorts              6) Exit
Please input your choice:

1)查看IP

Please input your choice:1
===============NetworkInfo===============
Host ip is: 10.0.2.15
Please input your choice:

2)查看CPU、內存、硬盤空間、網卡等信息

Please input your choice:2
===============HardwareInfo===============
ProductName: VirtualBox
CPU:         Intel(R) Pentium(R) Dual  CPU  E2140  @ 1.60GHz
PhysicMem:   801408 kB
DiskSpace:   12G 25%used
NetWorkCard: PCnet/PCI II 79C970A
Please input your choice:

3)查看系統和內核版本

Please input your choice:3
===============SystemInfo===============
Release:         release 6.4 (Final)
Kernal Version:  2.6.32-358.el6.i686
System Bits:     32 Bit
Please input your choice:

4)查看端口開放情況

Please input your choice:4
===============OpenPortsInfo===============
OpenPorts:
  127.0.0.1:9000    1430/php-fpm
    0.0.0.0:3306     1656/mysqld
     0.0.0.0:139       1771/smbd
     0.0.0.0:111    1103/rpcbind
      0.0.0.0:80      1423/nginx
      0.0.0.0:22       1815/sshd
   127.0.0.1:631      1292/cupsd
    127.0.0.1:25     1753/master
     0.0.0.0:445       1771/smbd
   0.0.0.0:46943  1187/rpc.statd
   127.0.0.1:199      1416/snmpd
          :::139       1771/smbd
          :::111    1103/rpcbind
           :::22       1815/sshd
         ::1:631      1292/cupsd
        :::60826  1187/rpc.statd
          :::445       1771/smbd

5)查看非默認登錄shell用戶

Please input your choice:5
===============UsersInfo===============
peanut:x:500:500:peanut:/home/peanut:/bin/bash
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
seg:x:502:502::/home/seg:/bin/bash
Please input your choice:

6)退出

Please input your choice:6
Bye

輸入錯誤

Please input your choice:a
Bad Choice
Please input your choice:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章