server_info.sh 3.27 KB
#!/bin/bash
# irul@20200907

if [[ `id -u` -ne 0 ]] ; then printf "\nPlease run as root.\n\n" ; exit 1 ; fi

clear

# https://www.2daygeek.com/bash-shell-script-view-linux-system-information/
echo -e "== System Information =="
echo -e "Manufacturer: "`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name: "`cat /sys/class/dmi/id/product_name`
echo -e "Version: "`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number: "`cat /sys/class/dmi/id/product_serial`
echo -e "Machine Type: "`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
echo -e "Kernel: "`uname -r`
echo -e "Architecture: "`arch`
echo -e "Processor Name: "`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo ""
echo -e "HDD: "`lsblk -dio SIZE,KNAME,MODEL,TYPE | grep disk`
echo -e "Memory(RAM): "`free -mht| awk '/Mem/{print $2 " |Used: " $3 " |Free: " $4}'`
echo -e "Swap Memory: "`free -mht| awk '/Swap/{print $2 " |Used: " $3 " |Free: " $4}'`
echo ""
# echo -e "Operating System: "`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`;
echo -e "Operating System: "`cat /etc/*release | grep PRETTY_NAME | cut -d "=" -f 2 | tr -d '"'`
echo -e "Using Systemd: "`pidof systemd && echo "True" || echo "False"`
echo -e "Hostname: "`hostname`
echo ""
# echo -e "Server IP: "`hostname -I`
echo -e "Server IP: "`/sbin/ip -4 a | grep "inet " | tail -n +2 | awk '{print $7 "=" $2}'`
echo -e "Default Gateway: "`ip route show | sed 's/\(\S\+\s\+\)\?default via \(\S\+\).*/\2/p; d'`
echo -e "Uptime: "`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo ""


echo -e "== Base Application =="

# virtualmin
if command -v virtualmin &> /dev/null
then
    echo "[x] virtualmin-"$(dpkg -l virtualmin-custom | grep ^ii | awk '{print $3}' | cut -f1 -d-)
else
    echo "[_] virtualmin"
fi
# webmin
if dpkg --get-selections | grep webmin &> /dev/null
then
    echo "[x] webmin-"$(dpkg -l webmin | grep ^ii | awk '{print $3}' | cut -f1 -d-)
else
    echo "[_] webmin"
fi
# openvpn
if command -v openvpn &> /dev/null
then
    echo "[x] openvpn-"$(openvpn --version | head -n 1 | cut -d " " -f 2)
else
    echo "[_] openvpn"
fi
# git
if command -v git &> /dev/null
then
    echo "[x] git-"$(git --version | head -n 1 | cut -d " " -f 3)
else
    echo "[_] git"
fi
# apache2
if dpkg --get-selections | grep -E '(^|\s)apache2($|\s)' &> /dev/null
then
    echo "[x] apache2-"$(dpkg -l apache2 | grep ^ii | awk '{print $3}' | cut -f1 -d-)
else
    echo "[_] apache2"
fi
# nginx
if dpkg --get-selections | grep nginx &> /dev/null
then
    echo "[x] nginx-"$(dpkg -l nginx | grep ^ii | awk '{print $3}' | cut -f1 -d-)
else
    echo "[_] nginx"
fi
# postgresql
if command -v psql &> /dev/null
then
    echo "[x] postgresql-"$(psql -V | head -n 1 | cut -d " " -f 3)
else
    echo "[_] postgresql"
fi
# mysql
if command -v mysql &> /dev/null
then
    echo "[x] mysql-"$(dpkg -l mysql-server | grep ^ii | awk '{print $3}' | cut -f1 -d-)
else
    echo "[_] mysql"
fi
# python3
if command -v python3 &> /dev/null
then
    echo "[x] python3-"$(python3 --version | head -n 1 | cut -d " " -f 2)
else
    echo "[_] python3"
fi
# php
if command -v php &> /dev/null
then
    echo "[x] php-"$(php -v | head -n 1 | cut -d " " -f 2)
else
    echo "[_] php"
fi

echo ""
echo "Last Check: "$(date '+%Y-%m-%d')
echo ""