Shell 硬件信息

简介: Shell 硬件信息

Shell 硬件信息

tags: 监控

  • HardwareInfo.sh
#!/usr/bin/env bash
# ------------------------------------------------------------------------ #
# Script Name:   hardware_machine.sh 
# Description:   Show informations about machine hardware.
# Written by:    Amaury Souza
# Maintenance:   Amaury Souza
# ------------------------------------------------------------------------ #
# Usage:         
#       $ ./hardware_machine.sh
# ------------------------------------------------------------------------ #
# Bash Version:  
#              Bash 4.4.19
# ------------------------------------------------------------------------ #
function menuprincipal () {
clear
TIME=1
echo " "
echo $0
echo " "
echo "Choose an option below!
        1 - Verify desktop processor
  2 - Verify system kernel
  3 - Verify installed softwares
  4 - Operation system version
        5 - Verify desktop memory
  6 - Verify serial number
  7 - Verify system IP   
  0 - Exit"
echo " "
echo -n "Chosen option: "
read opcao
case $opcao in
  1)
    function processador () {
      CPU_INFO=`cat /proc/cpuinfo | grep -i "^model name" | cut -d ":" -f2 | sed -n '1p'`
      echo "CPU model: $CPU_INFO"
      sleep $TIME
    } 
    processador
    read -n 1 -p "<Enter> for main menu"
    menuprincipal
    ;;
  2)
    function kernel () {
      #RED HAT: cat /etc/redhat-release
      KERNEL_VERSION_UBUNTU=`uname -r`
      KERNEL_VERSION_CENTOS=`uname -r`
      if [ -f /etc/lsb-release ]
      then
        echo "kernel version: $KERNEL_VERSION_UBUNTU"
      else
        echo "kernel version: $KERNEL_VERSION_CENTOS"
      fi
    }
    kernel
    read -n 1 -p "<Enter> for main menu"
    menuprincipal
    ;;
  3)
    function softwares () {
      #while true; do
      TIME=3
      echo " "
      echo "Choose an option below for program's list!
      1 - List Ubuntu programs
      2 - List Fedora programs
      3 - Install programs
      4 - Back to menu"
      echo " "
      echo -n "Chosen option: "
      read alternative
      case $alternative in
        1)
          echo "Listing all programs Ubuntu's systems..."
          sleep $TIME
          dpkg -l > /tmp/programs.txt
          echo Programs listed and available at /tmp
          sleep $TIME
          echo " "
                                        echo "Back to menu!" | tr [a-z] [A-Z]
          sleep $TIME
          ;;
        2)
          echo "Listing all programs Fedora's systems..."
          sleep $TIME
          yum list installed > /tmp/programs.txt
          echo Programs listed and available at /tmp
          sleep $TIME
          ;;
        3)
          echo Installing programss...
          LIST_OF_APPS="pinta brasero gimp vlc inkscape blender filezilla"
          #use aptitude command for programs loop.
          apt install aptitude -y
          aptitude install -y $LIST_OF_APPS
          ;;
        4)
          echo Back to main menu...
          sleep $TIME
          ;;  
      esac
    #done
    }   
    softwares
    menuprincipal
    ;;
  4)
    function sistema () {
      VERSION=`cat /etc/os-release | grep -i ^PRETTY`
      if [ -f /etc/os-release ]
      then
        echo "The system version: $VERSION"
      else
        echo "System not supported"
      fi
    }
    sistema
    read -n 1 -p "<Enter> for main menu"
    menuprincipal
    ;;
  5)
    function memory () {
      MEMORY_FREE=`free -m  | grep ^Mem | tr -s ' ' | cut -d ' ' -f 4`
      #MEMORY_TOTAL=
      #MEMORY_USED=
      echo Verifying system memory...
      echo "Memory free is: $MEMORY_FREE" 
    }
    memory
    read -n 1 -p "<Enter> for main menu"
    menuprincipal
    ;;
  6)
    function serial () {
      SERIAL_NUMBER=`dmidecode -t 1 | grep -i serial`
      echo $SERIAL_NUMBER
    }
    serial
    read -n 1 -p "<Enter> for main menu"
    menuprincipal
    ;;
  7)
    function ip () {
      IP_SISTEMA=`hostname -I`
      echo IP is: $IP_SISTEMA
    }
    ip
    read -n 1 -p "<Enter> for main menu"
    menuprincipal
    ;;
  0) 
         echo Exiting the system...
               sleep $TIME
         exit 0
         ;;
  *)
    echo Invalid option, try again!
    ;;
esac
}
menuprincipal

执行:

$ bash hardware_machine.sh
hardware_machine.sh
Choose an option below!
        1 - Verify desktop processor
        2 - Verify system kernel
        3 - Verify installed softwares
        4 - Operation system version
        5 - Verify desktop memory
        6 - Verify serial number
        7 - Verify system IP     
        0 - Exit
Chosen option: 1
CPU model:  Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
Chosen option: 7
IP is: 192.168.211.70 172.18.0.1 172.17.0.1
Chosen option: 2
kernel version: 4.15.0-180-generic
Chosen option: 3
Choose an option below for program's list!
                        1 - List Ubuntu programs
                        2 - List Fedora programs
                        3 - Install programs
                        4 - Back to menu
Chosen option: 5
Verifying system memory...
Memory free is: 698
Chosen option: 6
Serial Number: VMware-56 4d 67 71 20 7d eb e5-97 b4 bb 44 a3 d3 5f c6
相关文章
|
3天前
|
人工智能 监控 Shell
常用的 55 个 Linux Shell 脚本(包括基础案例、文件操作、实用工具、图形化、sed、gawk)
这篇文章提供了55个常用的Linux Shell脚本实例,涵盖基础案例、文件操作、实用工具、图形化界面及sed、gawk的使用。
14 2
|
23天前
|
Shell
Shell脚本有哪些基本语法?
【9月更文挑战第4天】
41 17
|
23天前
|
存储 Unix Shell
shell脚本编程基础
【9月更文挑战第4天】
35 12
|
22天前
|
网络协议 关系型数据库 MySQL
Shell 脚本案例
Shell 脚本案例
34 8
|
23天前
|
Shell Linux 开发工具
linux shell 脚本调试技巧
【9月更文挑战第3天】在Linux中调试shell脚本可采用多种技巧:使用`-x`选项显示每行命令及变量扩展情况;通过`read`或`trap`设置断点;利用`echo`检查变量值,`set`显示所有变量;检查退出状态码 `$?` 进行错误处理;使用`bashdb`等调试工具实现更复杂调试功能。
|
1月前
|
Ubuntu Linux Shell
在Linux中,如何使用shell脚本判断某个服务是否正在运行?
在Linux中,如何使用shell脚本判断某个服务是否正在运行?
|
1月前
|
Java Shell Linux
【Linux入门技巧】新员工必看:用Shell脚本轻松解析应用服务日志
关于如何使用Shell脚本来解析Linux系统中的应用服务日志,提供了脚本实现的详细步骤和技巧,以及一些Shell编程的技能扩展。
28 0
【Linux入门技巧】新员工必看:用Shell脚本轻松解析应用服务日志
|
1月前
|
监控 Shell Linux
在Linux中,如何使用shell脚本进行系统监控和报告?
在Linux中,如何使用shell脚本进行系统监控和报告?