最近在看《实战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: