|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +################################################################# |
| 4 | +# |
| 5 | +# Title : LinuxSystemHealth |
| 6 | +# |
| 7 | +# Description : Display system information at logon |
| 8 | +# |
| 9 | +# Author : Valentin Denis |
| 10 | +# |
| 11 | +# Creation date : 08-10-2019 |
| 12 | +# |
| 13 | +# Last modified : 27-12-2020 |
| 14 | +# |
| 15 | +# Version : 2.0 |
| 16 | +# |
| 17 | +################################################################ |
| 18 | + |
| 19 | +### Required packages |
| 20 | +## Centos : chronyd |
| 21 | + |
| 22 | + |
| 23 | +# Basic info |
| 24 | +HOSTNAME=`uname -n` |
| 25 | +SLASH=" / " |
| 26 | + |
| 27 | +## RAM Information |
| 28 | +MEMORY_TOTAL=`free -t -m | grep "Mem" | awk '{print $2" MB";}'` |
| 29 | +SWAP_USE=$(free -m | tail -n 1 | awk '{print $3}') |
| 30 | +SWAP_TOTAL=$(free -m | tail -n 1 | awk '{print $4}') |
| 31 | + |
| 32 | +## Disk Information |
| 33 | +# For root |
| 34 | + ROOT_USE=$(df -Ph / | grep /dev | awk '{print $3}')$SLASH |
| 35 | + ROOT_TOTAL=$(df -Ph / | grep /dev | awk '{print $2}') |
| 36 | + |
| 37 | +# For / share if exist |
| 38 | +if [ -d "/wikijs" ];then |
| 39 | + SHARE_USE=$(df -Ph /wikijs | grep /dev | awk '{print $3}')$SLASH |
| 40 | + SHARE_TOTAL=$(df -Ph /wikijs | grep /dev | awk '{print $2}') |
| 41 | +else |
| 42 | + SHARE_USE=$(echo "/share not found") |
| 43 | +fi |
| 44 | + |
| 45 | +### Different variable for Centos/Debian/Ubuntu |
| 46 | + |
| 47 | +if [ -f "/etc/redhat-release" ];then |
| 48 | + # For CentOS |
| 49 | + |
| 50 | + #Memory information |
| 51 | + MEMORY_USE=`free -t -m | grep Total | awk '{print $3" MB";}'` |
| 52 | + SYSTEM=$(cat /etc/redhat-release) |
| 53 | + IP=$(ip addr show eth0 | grep -Po 'inet \K[\d.]+') |
| 54 | +elif [ -f "/etc/issue" ];then |
| 55 | + # For Debian |
| 56 | + #Memory information |
| 57 | + MEMORY_USE=`free -t -m | grep buffers/cache: | awk '{print $3" MB";}'` |
| 58 | + SYSTEM=$(cat /etc/issue) |
| 59 | + IP=$(ifconfig eth0 | grep "inet ad" | cut -f2 -d: | awk '{print $1}') |
| 60 | +elif [ -f "/etc/lsb-release" ];then |
| 61 | + # For Ubuntu |
| 62 | + |
| 63 | + #Memory information |
| 64 | + MEMORY_USE=`free -t -m | grep buffers/cache: | awk '{print $3" MB";}'` |
| 65 | + SYSTEM=$(cat /etc/lsb-release) |
| 66 | +else |
| 67 | + #For Another |
| 68 | + SYSTEM=$(echo 'Not Detected') |
| 69 | +fi |
| 70 | + |
| 71 | +## LOAD Informations |
| 72 | +#LOAD 1 Minute |
| 73 | +LOAD1=`cat /proc/loadavg | awk {'print $1'}` |
| 74 | +#LOAD 5 Minutes |
| 75 | +LOAD2=`cat /proc/loadavg | awk {'print $2'}` |
| 76 | +#LOAD 15 Minutes |
| 77 | +LOAD3=`cat /proc/loadavg | awk {'print $3'}` |
| 78 | + |
| 79 | +## CPU Informations |
| 80 | +CPU_PERCENT=$(vmstat 1 2|tail -1 | awk '{print $13}') |
| 81 | +CPU_CORE=$(cat /proc/cpuinfo | grep -i "^processor" | wc -l) |
| 82 | + |
| 83 | +## Check SSH Service |
| 84 | +SSH_STATUS=`systemctl is-active sshd` |
| 85 | + |
| 86 | +#### Check Services |
| 87 | + |
| 88 | +## Check SNMP Service |
| 89 | +SNMP_STATUS=`systemctl is-active snmpd` |
| 90 | + |
| 91 | +## Check FTP Service |
| 92 | +FTP_STATUS=`systemctl is-active vsftpd` |
| 93 | + |
| 94 | +## Check SAMBA Service |
| 95 | +SAMBA_STATUS=`systemctl is-active smbd` |
| 96 | + |
| 97 | +## Check NTP Service |
| 98 | +NTP_STATUS=`systemctl is-active chronyd` |
| 99 | +NTP_SYNC_TEMP=$(timedatectl |grep 'NTP synchronized:') |
| 100 | +NTP_SYNC=${NTP_SYNC_TEMP:18} |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +echo " |
| 106 | +=============================================================== |
| 107 | + - Hostname....................: $HOSTNAME |
| 108 | + - System......................: $SYSTEM |
| 109 | + - /Share......................: $SHARE_USE$SHARE_TOTAL |
| 110 | + - /...........................: $ROOT_USE$ROOT_TOTAL |
| 111 | + - IP..........................: $IP |
| 112 | +=============================================================== |
| 113 | + - CPU usage...................: $CPU_PERCENT % |
| 114 | + - CPU Cores...................: $CPU_CORE |
| 115 | + - Load........................: $LOAD1 - $LOAD2 - $LOAD3 |
| 116 | + - Memory used.................: $MEMORY_USE / $MEMORY_TOTAL |
| 117 | + - Swap in use.................: $SWAP_USE MB / $SWAP_TOTAL MB |
| 118 | +=============================================================== |
| 119 | + - SSH.........................: $SSH_STATUS |
| 120 | + - Samba.......................: $SAMBA_STATUS |
| 121 | + - Chronyd (NTP)...............: $NTP_STATUS |
| 122 | + - NTP Synchronized.......: $NTP_SYNC |
| 123 | + - SNMP........................: $SNMP_STATUS |
| 124 | + - FTP.........................: $FTP_STATUS |
| 125 | +=============================================================== |
| 126 | +" |
0 commit comments