#!/bin/bash # Script name: FireMotD # Version: v12.05.191019 # Created on: 10/02/2014 # Author: Willem D'Haese # Purpose: Bash script which enables dynamic MotD messages # On GitHub: https://github.com/OutsideIT/FireMotD # On OutsideIT: https://outsideit.net/FireMotD # Copyright: # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. You should have received a copy of the # GNU General Public License along with this program. If not, see # . Debug=0 Verbose=0 HideVersion=0 SkipRepoUpdate=0 LogLocal='' ExportFile='/usr/share/firemotd/data/FireMotD.json' TemplateType='default' ScriptPath="$(readlink -f "$0")" ScriptName="$(basename "$ScriptPath")" ScriptVersion=" $(< "$ScriptPath" grep "# Version: " | head -n1 | awk '{print $3}' | tr -cd '[:digit:.-]' | sed 's/.\{0\}$//') " LC_ALL="C" LC_CTYPE="C" LC_NUMERIC="C" LANG="C" RenderTime="cache" WriteLog () { if [ -n "$ScriptName" ] ; then ScriptName="$(basename "$(readlink -f "$0")")" fi if [ -z "$1" ] ; then echo "WriteLog: Log parameter #1 is zero length. Please debug..." exit 1 else if [ -z "$2" ] ; then echo "WriteLog: Severity parameter #2 is zero length. Please debug..." exit 1 else if [ -z "$3" ] ; then echo "WriteLog: Message parameter #3 is zero length. Please debug..." exit 1 fi fi fi Now=$(date '+%Y-%m-%d %H:%M:%S,%3N') if [[ "$1" =~ (Debug|Verbose) ]] && [ "$Debug" = 1 ] ; then echo "$Now: $ScriptName: $2: $3 " elif [ "$1" = "Verbose" ] && [ "$Verbose" = 1 ] ; then echo "$Now: $ScriptName: $2: $3" elif [ "$1" = "Output" ] ; then echo "${Now}: $ScriptName: $2: $3" elif [ -f "$1" ] ; then echo "${Now}: $ScriptName: $2: $3" >> "$1" fi if [ -n "$LogLocal" ] ; then if [ "$1" = "Debug" ] && [ "$Debug" = 1 ] ; then echo "$Now: $ScriptName: $2: $3 " >> "$LogLocal" elif [ "$1" = "Verbose" ] && [ "$Verbose" = 1 ] ; then echo "$Now: $ScriptName: $2: $3" >> "$LogLocal" elif [ "$1" = "Output" ] ; then echo "${Now}: $ScriptName: $2: $3" >> "$LogLocal" fi fi } ColorTest () { ColorMap=1; [[ (-n $1) && ($1 -eq 0) ]] && ColorMap=0 echo -n -e "\n\e[1mYour terminal \e[4mdoes not\e[24m support 256 colors if:\e[0m\n" echo " * The Color Cube colors are the same as System Colors" echo " * Your gray scale ramp has only 3 variations" echo -n -e "\nSystem colors:\n" for code in {0..15}; do ds=" " if [[ $ColorMap -eq 0 ]]; then [[ $code -lt 10 ]] && ds=" $code " || ds=" $code " fi echo -n -e "\e[48;05;${code}m${ds}" [[ ($code -eq 7) || ($code -eq 15) ]] && echo -n -e "\e[0m\n" done tcolor=255 echo -n -e "\nColor cube, 6x6x6:\n" for green in {0..5}; do for red in {0..5}; do for blue in {0..5}; do color=$((16 + (red * 36) + (green * 6) + blue)); ds=" " if [[ $ColorMap -eq 0 ]]; then [[ $color -lt 100 ]] && ds="$color " || ds="$color " fi echo -n -e "\e[38;05;${tcolor}m\e[48;05;${color}m${ds}" done echo -n -e "\e[0m " done echo -n -e "\e[0m\n" tcolor=0 done tcolor=255 echo -n -e "\nGrayscale ramp:\n" for gray in {232..255}; do [[ $gray -gt 245 ]] && tcolor=0 ds=" " [[ $ColorMap -eq 0 ]] && ds=" $gray " echo -n -e "\e[38;05;${tcolor}m\e[48;05;${gray}m${ds}" done echo -e "\e[0;37m\e[0m\n" } ContainsValidIp () { WriteLog Verbose Info "Checking if $1 contains an ip" local ip=$1 local stat=1 Extract=$(echo "$ip" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1) WriteLog Verbose Info "Extract: $Extract" if [[ $Extract =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then OIFS=$IFS IFS='.' Extract=($Extract) IFS=$OIFS [[ ${Extract[0]} -le 255 && ${Extract[1]} -le 255 && ${Extract[2]} -le 255 && ${Extract[3]} -le 255 ]] stat=$? WriteLog Verbose Info "Match result: $?" fi return $stat } VersionComparison () { if [[ "$1" == "$2" ]] ; then echo "equal" return 0 fi local IFS=. local i ver1=($1) ver2=($2) for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) ; do ver1[i]=0 done for ((i=0; i<${#ver1[@]}; i++)) ; do if [[ -z ${ver2[i]} ]] ; then ver2[i]=0 fi if ((10#${ver1[i]} > 10#${ver2[i]})) ; then echo "older" return 1 fi if ((10#${ver1[i]} < 10#${ver2[i]})) ; then echo "newer" return 2 fi done echo "unknown" return 3 } IsInstalled () { if [[ -x "/usr/bin/yum" ]] ; then YumExec=$(command -v yum 2>/dev/null) if $YumExec list installed "$@" >/dev/null 2>&1; then true ; else false ; fi elif [[ -x "/usr/bin/zypper" ]] ; then WriteLog Verbose Info "No install check for zypper available." true elif [[ -x "/usr/bin/apt-get" ]] ; then if dpkg-query -l "$@" >/dev/null 2>&1 ; then true ; else false ; fi fi } GetSessions () { WriteLog Verbose Info "Output who: $(who)" WriteLog Verbose Info "Output who: $(who | cut -d' ' -f1,14)" SessionCount="$(who | cut -d' ' -f1,12 | tr ' ' @ | tr '\n' ',' | tr -d '()' | rev | cut -c 2- | rev)" WriteLog Verbose Info "SessionCount 1: f1,12: $SessionCount" CleanSessionHost=$(echo "$SessionCount" | cut -d, -f2 | cut -d@ -f2- | cut -d@ -f2- ) WriteLog Verbose Info "CleanSessionhost: $CleanSessionHost" RegexHost="^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.){6,}*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]){6,}$" if ! ContainsValidIp "$SessionCount" ; then WriteLog Verbose Info "SessionCount $SessionCount does not contain an ip address. " if ! [[ "$CleanSessionHost" =~ $RegexHost ]] ; then WriteLog Verbose Info "CleanSessionHost $CleanSessionHost does not contain a hostname. " SessionCount="$(who | cut -d' ' -f1,13 | tr ' ' @ | tr '\n' ',' | tr -d '()' | rev | cut -c 2- | rev)" WriteLog Verbose Info "SessionCount 2: f1,13: $SessionCount" if ! ContainsValidIp "$SessionCount" && ! [[ "$CleanSessionHost" =~ $RegexHost ]] ; then SessionCount="$(who | cut -d' ' -f1,14 | tr ' ' @ | tr '\n' ',' | tr -d '()' | rev | cut -c 2- | rev)" WriteLog Verbose Info "SessionCount 3: f1,14: $SessionCount" fi else SessionCount="$(who | cut -d' ' -f1,12 | tr ' ' @ | tr '\n' ',' | tr -d '()' | rev | cut -c 2- | rev)" WriteLog Verbose Info "CleanSessionHost $CleanSessionHost contains a hostname. " fi else WriteLog Verbose Info "SessionCount $SessionCount contains an ip address. " fi } ExploreHostName () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') HostName="$(hostname)" tmp=$(mktemp) jq ".HostName.Value = \"$HostName\" |\ .HostName.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreHostIp () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') IpPath="$(command -v ip 2>/dev/null)" if [ -z "$IpPath" ] ; then if [ -f /usr/sbin/ip ] ; then IpPath="/usr/sbin/ip" elif [ -f /sbin/ip ] ; then IpPath="/sbin/ip" else WriteLog Verbose Warning "Path doesn't contain ip tool" fi fi if [[ -n $IpPath ]] ; then HostIp="$(${IpPath} route get 8.8.8.8 | head -1 | grep -Po '(?<=src )(\d{1,3}.){4}' | xargs)" if [[ ! $HostIp =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then HostIp="Unable to parse ip $HostIp. Please debug." fi else HostIp="Unable to use ip route. Please debug." fi if [ -f /sys/hypervisor/uuid ] && [ "$(head -c 3 /sys/hypervisor/uuid)" == ec2 ]; then CurlExec=$(command -v curl 2>/dev/null) WgetExec=$(command -v wget 2>/dev/null) if [[ (-f $CurlExec) && (-x $CurlExec) ]]; then HostIp=$($CurlExec -s http://instance-data/latest/meta-data/public-ipv4) elif [[ (-f $WgetExec) && (-x $WgetExec) ]]; then HostIp=$($WgetExec -qO- http://instance-data/latest/meta-data/public-ipv4) fi fi tmp=$(mktemp) jq ".HostIp.Value = \"$HostIp\" |\ .HostIp.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreRelease () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') ReleaseFull="$(cat /etc/*release)" Release="$(echo "$ReleaseFull" | head -n 1)" if echo "$ReleaseFull" | grep -E '(^CentOS*|^Red Hat*)' >/dev/null ; then Release="$(echo "$ReleaseFull" | tail -1)" elif echo "$ReleaseFull" | grep -E '(Debian)' >/dev/null ; then Release="$(echo "$ReleaseFull" | grep 'PRETTY_NAME' | cut -f2 -d'"')" elif [[ "$Release" == "SUSE"* ]] ; then Release=${Release%% \(*} PatchLevel="$(cat /etc/*release | sed -n 3p | sed 's/.*= //')" Release="${Release}.$PatchLevel" elif [[ "$Release" == "openSUSE"* ]] ; then Release="$(< /etc/os-release sed -n 4p | sed 's/PRETTY_NAME="//' | sed 's/ (.*//')" elif [[ "$Release" == *"Raspbian"* ]] ; then Release="$(echo "$ReleaseFull" | head -n 1 | sed 's/.*"\(.*\)"[^"]*$/\1/')" elif [[ "$ReleaseFull" == *"DISTRIB_DESCRIPTION"* ]] ; then Release="$(echo "$ReleaseFull" | grep 'DISTRIB_DESCRIPTION' | cut -f2 -d'"')" fi tmp=$(mktemp) jq ".Release.Value = \"$Release\" |\ .Release.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreKernel () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') Kernel="$(uname -rs)" tmp=$(mktemp) jq ".Kernel.Value = \"$Kernel\" |\ .Kernel.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExplorePlatform () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') Dmesg="$(dmesg 2>/dev/null)" Dmi="$(echo "$Dmesg" | grep "DMI:")" Rasp="$(echo "$Dmesg" | grep "Raspberry")" Xen="$(echo "$Dmesg" | grep -i 'xen version')" [[ -f "/proc/1/comm" ]] && InitSystem="$(cat /proc/1/comm)" if [[ "$Dmi" = *"QEMU"* ]] ; then Platform="$(echo "$Dmi" | sed 's/^.*QEMU/QEMU/' | sed 's/, B.*//')" elif [[ "$Dmi" = *"VMware"* ]] ; then Platform="$(echo "$Dmi" | sed 's/^.*VMware/VMware/' | sed 's/, B.*//')" elif [[ "$Dmi" = *"FUJITSU PRIMERGY"* ]] ; then Platform="$(echo "$Dmi" | sed 's/^.*FUJITSU PRIMERGY/Fujitsu Primergy/' | sed 's/, B.*//')" elif [[ "$Dmi" = *"HP"* ]] ; then Platform="$(echo "$Dmi" | sed 's/^.*Hewlett-Packard HP ProBook/HP Probook/' | sed 's/, B.*//')" elif [[ "$Dmi" = *"VirtualBox"* ]] ; then Platform="$(echo "$Dmi" | sed 's/^.*VirtualBox/VirtualBox/' | sed 's/ .*//')" elif [[ "$Dmi" = *"DMI:"* ]] ; then Platform="$(echo "$Dmi" | sed -n -e 's/^.*DMI: //p')" elif [[ "$Dmi" = *"klogctl"* ]] ; then Platform="Windows Subsytem for Linux" elif [[ "$Xen" = *"Xen version"* ]] ; then Platform="Xen Hypervisor v""$(echo "$Xen" | sed -n -e 's/^.*Xen version: //p')" elif [[ "$Rasp" = *"Rasp"* ]] ; then Platform=${Rasp//*: /} elif [[ $(uname -r) =~ pine64-longsleep ]] ; then Platform="Pine A64" _mem="$(< /proc/meminfo grep MemTotal | awk '{print $2}')" if [ "$_mem" -gt 500000 ] && [ "$_mem" -gt 503000 ]; then Platform="Pine A64 512MB Rev B Board"; fi if [ "$_mem" -gt 1000000 ] && [ "$_mem" -gt 1006000 ]; then Platform="Pine A64+ 1GB Rev B Board"; fi if [ "$_mem" -gt 2000000 ] && [ "$_mem" -gt 2012000 ]; then Platform="Pine A64+ 2GB Rev C Board"; fi elif [[ $(uname -r) =~ Microsoft ]] ; then Platform="Windows Subsystem for Linux" elif [[ "$InitSystem" == "systemd" ]] ; then Custom="$(systemd-detect-virt)" if [[ -n $Custom ]] ; then if [[ "$Custom" = *"openvz"* ]] ; then Platform="OpenVZ" elif [[ "$Custom" = *"vmware"* ]] ; then Platform="VMware Virtual Platform" else Platform=$Custom fi else Platform="Unknown" fi else Platform="Unknown" fi tmp=$(mktemp) jq ".Platform.Value = \"$Platform\" |\ .Platform.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreUptime () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') UptimeDays=$(awk '{print int($1/86400)}' /proc/uptime) UptimeHours=$(awk '{printf("%02d", int($1%86400/3600))}' /proc/uptime) UptimeMinutes=$(awk '{printf("%02d", int(($1%3600)/60))}' /proc/uptime) UptimeSeconds=$(awk '{printf("%02d", int($1%60))}' /proc/uptime) tmp=$(mktemp) jq ".Uptime.Days = \"$UptimeDays\" |\ .Uptime.Hours = \"$UptimeHours\" |\ .Uptime.Minutes = \"$UptimeMinutes\" |\ .Uptime.Seconds = \"$UptimeSeconds\" |\ .Uptime.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreInstallDate () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') RpmPath="$(command -v rpm 2>/dev/null)" if [[ (-f $RpmPath) && (-x $RpmPath) ]] ; then InstallDate=$(rpm -qi basesystem | grep "Install Date" | sed 's/Install Date: //g' | sed 's/Build Host: .*//g') fi tmp=$(mktemp) jq ".InstallDate.Value = \"$InstallDate\" |\ .InstallDate.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreCpuUsage () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') CpuUsageAverage="$(LANG=en_GB.UTF-8 mpstat | awk '$2 ~ /CPU/ { for(i=1;i<=NF;i++) { if ($i ~ /%idle/) field=i } } $2 ~ /all/ { print 100 - $field}' | tail -1)" CpuUsageCpuCount="$(< /proc/cpuinfo grep -c processor)" if [[ "$(jq -r ".Platform.Value" $ExportFile)" == "OpenVZ" ]] ; then CpuUsageSocketCount="$(< /proc/cpuinfo grep "physical id" | sort -u | wc -l)" CpuUsageCoreCount="$(< /proc/cpuinfo grep "processor" | sort -u | wc -l)" else CpuUsageSocketCount="$(lscpu | grep 'Socket(s):' | head -1 | awk -F " " '{print $2}')" CpuUsageCoreCount="$(lscpu | grep 'Core(s) per socket:' | head -1 | awk -F " " '{print $4}')" fi tmp=$(mktemp) jq ".CpuUsage.Average = \"$CpuUsageAverage\" |\ .CpuUsage.CpuCount = \"$CpuUsageCpuCount\" |\ .CpuUsage.CoreCount = \"$CpuUsageCoreCount\" |\ .CpuUsage.SocketCount = \"$CpuUsageSocketCount\" |\ .CpuUsage.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreCpuLoad () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') CpuLoad="$(uptime | grep -ohe '[s:][: ].*' | awk '{print "1m: "$2 " 5m: "$3 " 15m: " $4}')" tmp=$(mktemp) jq ".CpuLoad.Value = \"$CpuLoad\" |\ .CpuLoad.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreMemory () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') MemTotalB="$(< /proc/meminfo grep MemTotal | awk '{print $2}')" MemTotalGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;"$MemTotalB"/1024/1024)")" ProcpsVersion="$(free -V | awk '{ print $4 }')" Result=$(VersionComparison 3.3.9 "$ProcpsVersion") if [[ $Result =~ (older|equal) ]] ; then MemFreeB="$(free | grep buffers/cache | awk '{print $4}')" MemUsedB="$(free | grep buffers/cache | awk '{print $3}')" else MemBuffCacheB="$(free | awk '/Mem:/ { print $6 }')" MemFreeUsedB="$(free | awk '/Mem:/ { print $3 }')" MemUsedB=$(echo "$MemBuffCacheB+$MemFreeUsedB" | bc) MemFreeB="$(free | awk '/Mem:/ { print $4 }')" fi MemFreeGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;"$MemFreeB"/1024/1024)")" MemUsedGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;"$MemUsedB"/1024/1024)")" MemFreePerc=$(echo "scale=2; $MemFreeB*100/$MemTotalB" | bc) MemFreePerc="$(LC_NUMERIC=C printf "%.0f" "$MemFreePerc")" MemUsedPerc=$(echo "100-$MemFreePerc" | bc) tmp=$(mktemp) jq ".Memory.TotalGB = \"$MemTotalGB\" |\ .Memory.FreeGB = \"$MemFreeGB\" |\ .Memory.UsedGB = \"$MemUsedGB\" |\ .Memory.FreePerc = \"$MemFreePerc\" |\ .Memory.UsedPerc = \"$MemUsedPerc\" |\ .Memory.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreSwap () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') SwapTotalB="$(< /proc/meminfo grep SwapTotal | awk '{print $2}')" SwapTotalGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;"$SwapTotalB"/1024/1024)")" SwapFreeB="$(< /proc/meminfo grep SwapFree | awk '{print $2}')" SwapFreeGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;"$SwapFreeB"/1024/1024)")" SwapUsedB="$((SwapTotalB - SwapFreeB))" SwapUsedGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;$SwapUsedB/1024/1024)")" SwapFreePerc=$(echo "scale=2; $SwapFreeB*100/$SwapTotalB" | bc 2> /dev/null) SwapFreePerc="$(LC_NUMERIC=C printf "%.0f" "$SwapFreePerc")" SwapUsedPerc=$(echo "100-$SwapFreePerc" | bc) tmp=$(mktemp) jq ".Swap.TotalGB = \"$SwapTotalGB\" |\ .Swap.FreeGB = \"$SwapFreeGB\" |\ .Swap.UsedGB = \"$SwapUsedGB\" |\ .Swap.FreePerc = \"$SwapFreePerc\" |\ .Swap.UsedPerc = \"$SwapUsedPerc\" |\ .Swap.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreDiskRoot () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') DiskRootTotalB="$(df -kP / | tail -1 | awk '{print $2}')" DiskRootTotalGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;"$DiskRootTotalB"/1024/1024)")" DiskRootFreeB="$(df -kP / | tail -1 | awk '{print $4}')" DiskRootFreeGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;"$DiskRootFreeB"/1024/1024)")" DiskRootUsedB="$(df -kP / | tail -1 | awk '{print $3}')" DiskRootUsedGB="$(printf "%0.2f\n" "$(bc -q <<< scale=2\;"$DiskRootUsedB"/1024/1024)")" DiskRootUsedPerc="$(df -kP / | tail -1 | awk '{print $5}'| sed s'/%$//')" DiskRootFreePerc="$((100 - DiskRootUsedPerc))" tmp=$(mktemp) jq ".DiskRoot.TotalGB = \"$DiskRootTotalGB\" |\ .DiskRoot.FreeGB = \"$DiskRootFreeGB\" |\ .DiskRoot.UsedGB = \"$DiskRootUsedGB\" |\ .DiskRoot.FreePerc = \"$DiskRootFreePerc\" |\ .DiskRoot.UsedPerc = \"$DiskRootUsedPerc\" |\ .DiskRoot.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreUpdates () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') if [[ -x "/usr/bin/yum" ]] ; then UpdateType="yum" YumExec=$(command -v yum 2>/dev/null) UpdateCount=$(($($YumExec -d 0 check-update 2>/dev/null | wc -l)-1)) if [ $UpdateCount == -1 ]; then UpdateCount=0 fi elif [[ -x "/usr/bin/zypper" ]] ; then UpdateType="zypper" UpdateCount=$(zypper list-updates | wc -l) UpdateCount=$((UpdateCount-4)) if ((UpdateCount<=0)) ; then UpdateCount=0 fi elif [[ -x "/usr/bin/apt-get" ]] ; then UpdateType="apt" if [[ "$SkipRepoUpdate" -eq 1 ]]; then UpdateCount=$(apt-get upgrade -u -s | grep -c -P "^Inst") else UpdateCount=$(apt-get update > /dev/null; apt-get upgrade -u -s | grep -c -P "^Inst") fi fi tmp=$(mktemp) jq ".Updates.Type = \"$UpdateType\" |\ .Updates.Count = \"$UpdateCount\" |\ .Updates.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreSessions () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') SessionCount="$(who | grep -c "$USER")" tmp=$(mktemp) jq ".Sessions.Count = \"$SessionCount\" |\ .Sessions.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreProcesses () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') ProcessCount="$(ps -A --no-headers | wc -l)" SysctlPath="$(command -v sysctl 2>/dev/null)" if [ -z "$SysctlPath" ] ; then if [ -f /usr/sbin/sysctl ] ; then SysctlPath="/usr/sbin/sysctl" elif [ -f /sbin/sysctl ] ; then SysctlPath="/sbin/sysctl" else WriteLog Verbose Warning "Path doesn't contain sysctl tool" fi fi ProcessMax="$($SysctlPath -n kernel.pid_max)" tmp=$(mktemp) jq ".Processes.Count = \"$ProcessCount\" |\ .Processes.Max = \"$ProcessMax\" |\ .Processes.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreHttpd () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') HttpdPath="$(command -v httpd 2>/dev/null)" [[ ! -f $HttpdPath ]] && HttpdPath="/usr/sbin/apache2ctl" [[ ! -f $HttpdPath ]] && HttpdPath="/usr/sbin/apache2" if [[ (-f $HttpdPath) && (-x $HttpdPath) ]] ; then HttpdVersion="$(${HttpdPath} -v 2>/dev/null | grep "Server version" | sed -e 's/.*[^0-9]\([0-9].[0-9]\+.[0-9]\+\)[^0-9]*$/\1/')" fi tmp=$(mktemp) jq ".Httpd.Version = \"$HttpdVersion\" |\ .Httpd.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreNginx () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') NginxVersion="" NginxPath="$(command -v nginx 2>/dev/null)" if [[ (-f $NginxPath) && (-x $NginxPath) ]] ; then NginxString="$(${NginxPath} -v 2>&1)" NginxVersion="$(echo "$NginxString" | awk -F"/" '{print $2}')" fi tmp=$(mktemp) jq ".Nginx.Version = \"$NginxVersion\" |\ .Nginx.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreMysql () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') MysqlVersion="" MysqlDistribution="" MysqlPath="$(command -v mysql 2>/dev/null)" if [[ (-f $MysqlPath) && (-x $MysqlPath) ]] ; then MysqlString="$(${MysqlPath} --version 2>/dev/null)" MysqlVersion="$(echo "$MysqlString" | awk '{print $3}')" MysqlDistribution="$(echo "$MysqlString" | awk '{print $5}' | tr -d ',')" fi tmp=$(mktemp) jq ".Mysql.Version = \"$MysqlVersion\" |\ .Mysql.Distribution = \"$MysqlDistribution\" |\ .Mysql.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExplorePostgres () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') PostgresVersion="" PostgresPath="$(command -v psql 2>/dev/null)" if [[ (-f $PostgresPath) && (-x $PostgresPath) ]] ; then PostgresString="$(${PostgresPath} --version 2>/dev/null)" PostgresVersion="$(echo "$PostgresString" | head -n1 | awk '{print $3}')" fi tmp=$(mktemp) jq ".Postgres.Version = \"$PostgresVersion\" |\ .Postgres.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExplorePhp () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') PhpVersion="$(/usr/bin/php -v 2>/dev/null | grep -oE '^PHP\s[0-9]+\.[0-9]+\.[0-9]+' | awk '{ print $2}')" if [ -f /etc/php.ini ] ; then PhpIniPath="/etc/php.ini" elif [ -f /etc/php5/fpm/php.ini ] ; then PhpIniPath="/etc/php5/fpm/php.ini" fi if [ -n "$PhpIniPath" ] ; then PhpMaxMemory=$(tac $PhpIniPath | grep -F -m 1 memory_limit | sed -n 's/.* = \([0-9]*\)/\1/p' | sed 's/; .*//g') if [[ "$PhpMaxMemory" == "-1" ]]; then PhpMaxMemory="Unlimited" fi fi tmp=$(mktemp) jq ".Php.Version = \"$PhpVersion\" |\ .Php.MaxMemory = \"$PhpMaxMemory\" |\ .Php.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreElasticsearch () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') if [[ -x "/usr/bin/yum" ]] ; then ElasticsearchVersion=$(/usr/bin/yum info -v elasticsearch 2>/dev/null | grep -A12 -B5 -w installed | grep Version | awk '{print $3}') else ElasticsearchVersion="Unknown" fi if [ -z $ElasticsearchVersion ] || [[ $ElasticsearchVersion == *"Error: No matching Packages"* ]] ; then ElasticsearchVersion="Unknown" fi tmp=$(mktemp) jq ".Elasticsearch.Version = \"$ElasticsearchVersion\" |\ .Elasticsearch.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreLogstash () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') if [[ -x "/usr/bin/yum" ]] ; then LogstashVersion=$(/usr/bin/yum info -v logstash 2>/dev/null | grep -A12 -B5 -w installed | grep Version | awk '{print $3}') else LogstashVersion="Unknown" fi if [ -z $LogstashVersion ] || [[ $LogstashVersion == *"Error: No matching Packages"* ]] ; then LogstashVersion="Unknown" fi tmp=$(mktemp) jq ".Logstash.Version = \"$LogstashVersion\" |\ .Logstash.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExploreKibana () { ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') if [[ -x "/usr/bin/yum" ]] ; then KibanaVersion=$(/usr/bin/yum info -v kibana 2>/dev/null | grep -A12 -B5 -w installed | grep Version | awk '{print $3}') else KibanaVersion="Unknown" fi if [ -z $KibanaVersion ] || [[ $KibanaVersion == *"Error: No matching Packages"* ]] ; then KibanaVersion="Unknown" fi tmp=$(mktemp) jq ".Kibana.Version = \"$KibanaVersion\" |\ .Kibana.LastRun = \"$ExportTime\"" $ExportFile > "$tmp" && cp "$tmp" $ExportFile rm $tmp } ExportData () { if [ ! -d "/usr/share/firemotd/templates" ]; then WriteLog Output Error "Template folder doesn't exist. Upgrading from an older version? Please run make again or run the install function \"FireMotD -I -v\"." exit 2 elif [[ -s "$ExportFile" ]] ; then WriteLog Debug Info "Exportfile $ExportFile found." if [[ "$TemplateType" != "default" ]] ; then if [[ -s "/usr/share/firemotd/templates/FireMotD-template-${TemplateType}.json" ]] ; then WriteLog Verbose Info "Template type set to ${TemplateType}. Overwriting.." cp "/usr/share/firemotd/templates/FireMotD-template-${TemplateType}.json" $ExportFile else WriteLog Output Error "Template ${TemplateType} does not exist. Try running the install function \"FireMotD -I -v\"." exit 2 fi else if [[ ! -f "$ExportFile" ]] ; then TemplateType="basic" cp "/usr/share/firemotd/templates/FireMotD-template-${TemplateType}.json" $ExportFile fi fi else WriteLog Debug Info "Exportfile $ExportFile not found. " if [[ "$TemplateType" != "default" ]] ; then if [[ -s "/usr/share/firemotd/templates/FireMotD-template-${TemplateType}.json" ]] ; then WriteLog Verbose Info "Template type set to ${TemplateType}. Overwriting.." cp "/usr/share/firemotd/templates/FireMotD-template-${TemplateType}.json" $ExportFile else WriteLog Output Error "Template ${TemplateType} does not exist. Try running the install function \"FireMotD -I - v\"." exit 2 fi else if [[ ! -f "$ExportFile" ]] ; then TemplateType="basic" cp "/usr/share/firemotd/templates/FireMotD-template-${TemplateType}.json" $ExportFile fi fi fi ExportTime=$(date '+%Y-%m-%d %H:%M:%S,%3N') while read -r val ; do WriteLog Debug Info "Exploring ${val}" "Explore${val}" done < <(jq -r 'to_entries[] | select(.value.Generated == "@cron") | .key' $ExportFile) WriteLog Verbose Info "Export system data to \"${ExportFile}\" finished." chmod 0766 ${ExportFile} LsExport=$(ls -la ${ExportFile}) WriteLog Debug Info "ExportFile: $LsExport" } LoadData () { WriteLog Verbose Info "Logon data refresh start" if [[ -s "$ExportFile" ]] ; then i=0 if [[ "$MultiThreaded" == "1" ]] ; then Procs=$(nproc --all) (( Procs++ )) fi while read -r val ; do if [[ "$MultiThreaded" == "1" ]] ; then WriteLog Verbose Info "Exploring ${val} in background job $i" "Explore${val}" & RunningJobs=$(jobs -r | wc -l | tr -d " ") WriteLog Verbose Info "$RunningJobs jobs running." while [ "$(jobs -r | wc -l | tr -d " ")" -gt "$Procs" ] ; do WriteLog Debug Info "More then $Procs jobs running. Waiting for completion" sleep 0.1 done (( i++ )) else WriteLog Verbose Info "Exploring ${val}" "Explore${val}" if [[ $(id -u) == 0 ]] ; then chmod 0766 ${ExportFile} fi LsExport=$(ls -la ${ExportFile}) WriteLog Debug Info "ExportFile: $LsExport" fi done < <(jq -r 'to_entries[] | select(.value.Generated == "@logon") | .key' $ExportFile) if [[ "$MultiThreaded" == "1" ]] ; then WriteLog Verbose Info "Waiting for all background explorers to finish" wait fi else WriteLog Output Info "No FireMotD ExportFile detected. Please generate with \"sudo .\/FireMotD -S\"" exit 2 fi WriteLog Verbose Info "Logon Data refresh for end" } StartOriginalBlue () { for i in {18..21} {21..18} ; do ShortBlueScheme+="\e[38;5;${i}m#\e[0m" ; done ; for i in {17..21} {21..17} ; do BlueScheme+="\e[38;5;${i}m#\e[0m\e[38;5;${i}m#\e[0m" ; done ; for i in {17..21} {21..17} ; do LongBlueScheme+="\e[38;5;${i}m#\e[0m\e[38;5;${i}m#\e[0m\e[38;5;${i}m#" ; done ; } GenerateOriginal256Color () { WriteLog Verbose Info "Generating 256 color $Theme FireMotD" Space="" if [[ "$Theme" == "Modern" ]] ; then Space=" " Fto=" " else Fto="##" fi ShownVersion="" if [[ "$HideVersion" -eq 1 ]]; then ShownVersion="$CP1$CP1$CP1$CP1$CP1$CP1" else ShownVersion="$ScriptVersion" fi HostName=$(jq -r ".HostName.Value" $ExportFile) if [[ "$HostName" != "null" ]] && [[ "$HostName" != "" ]] ; then echo -e "$BlueScheme$LongBlueScheme$BlueScheme$ShortBlueScheme $BlueScheme \e[38;5;93m $HostName $ShortBlueScheme $Space\e[38;5;98m$SVC$ShownVersion $BlueScheme$LongBlueScheme$BlueScheme$ShortBlueScheme" fi HostIp=$(jq -r ".HostIp.Value" $ExportFile) if [[ -n $HostIp ]] && [[ "$HostIp" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mIp \e[38;5;93m= \e[38;5;33m$HostIp" fi Release=$(jq -r ".Release.Value" $ExportFile) if [[ -n $Release ]] && [[ "$Release" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mRelease \e[38;5;93m= \e[38;5;27m$Release" fi Kernel=$(jq -r ".Kernel.Value" $ExportFile) if [[ -n $Kernel ]] && [[ "$Kernel" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mKernel \e[38;5;93m= \e[38;5;27m$Kernel" fi Platform=$(jq -r ".Platform.Value" $ExportFile) if [[ -n $Platform ]] && [[ "$Platform" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mPlatform \e[38;5;93m= \e[38;5;27m$Platform" fi UptimeDays=$(jq -r ".Uptime.Days" $ExportFile) UptimeHours=$(jq -r ".Uptime.Hours" $ExportFile) UptimeMinutes=$(jq -r ".Uptime.Minutes" $ExportFile) UptimeSeconds=$(jq -r ".Uptime.Seconds" $ExportFile) if [[ -n $UptimeDays ]] && [[ "$UptimeDays" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mUptime \e[38;5;93m= \e[38;5;33m${UptimeDays} \e[38;5;27mday(s). \e[38;5;33m${UptimeHours}\e[38;5;27m:\e[38;5;33m${UptimeMinutes}\e[38;5;27m:\e[38;5;33m${UptimeSeconds}" fi InstallDate=$(jq -r ".InstallDate.Value" $ExportFile) if [[ -n $InstallDate ]] && [[ "$InstallDate" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mInstalled \e[38;5;93m= \e[38;5;27m$InstallDate" fi CpuUsageAverage=$(jq -r ".CpuUsage.Average" $ExportFile) CpuUsageCpuCount=$(jq -r ".CpuUsage.CpuCount" $ExportFile) CpuUsageCoreCount=$(jq -r ".CpuUsage.CoreCount" $ExportFile) CpuUsageSocketCount=$(jq -r ".CpuUsage.SocketCount" $ExportFile) if [[ -n $CpuUsageAverage ]] && [[ "$CpuUsageAverage" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mCPU Usage \e[38;5;93m= \e[38;5;33m${CpuUsageAverage}\e[38;5;27m% avg over \e[38;5;33m$CpuUsageCpuCount \e[38;5;27mcpu(s) ($CpuUsageCoreCount core(s) x $CpuUsageSocketCount socket(s))" fi CpuLoad=$(jq -r ".CpuLoad.Value" $ExportFile) if [[ -n $CpuLoad ]] && [[ "$CpuLoad" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mCPU Load \e[38;5;93m= \e[38;5;27m$CpuLoad" fi MemTotalGB=$(jq -r ".Memory.TotalGB" $ExportFile) MemFreeGB=$(jq -r ".Memory.FreeGB" $ExportFile) MemUsedGB=$(jq -r ".Memory.UsedGB" $ExportFile) MemFreePerc=$(jq -r ".Memory.FreePerc" $ExportFile) MemUsedPerc=$(jq -r ".Memory.UsedPerc" $ExportFile) if [[ -n $MemTotalGB ]] && [[ "$MemTotalGB" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mMemory \e[38;5;93m= \e[38;5;27mFree: \e[38;5;33m${MemFreeGB}\e[38;5;27mGB (\e[38;5;33m${MemFreePerc}\e[38;5;27m%), Used: \e[38;5;33m${MemUsedGB}\e[38;5;27mGB (\e[38;5;33m${MemUsedPerc}\e[38;5;27m%), Total: \e[38;5;33m${MemTotalGB}\e[38;5;27mGB" fi SwapTotalGB=$(jq -r ".Swap.TotalGB" $ExportFile) SwapFreeGB=$(jq -r ".Swap.FreeGB" $ExportFile) SwapUsedGB=$(jq -r ".Swap.UsedGB" $ExportFile) SwapFreePerc=$(jq -r ".Swap.FreePerc" $ExportFile) SwapUsedPerc=$(jq -r ".Swap.UsedPerc" $ExportFile) if [[ -n $SwapTotalGB ]] && [[ "$SwapTotalGB" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mSwap \e[38;5;93m= \e[38;5;27mFree: \e[38;5;33m${SwapFreeGB}\e[38;5;27mGB (\e[38;5;33m$SwapFreePerc\e[38;5;27m%), Used: \e[38;5;33m${SwapUsedGB}\e[38;5;27mGB (\e[38;5;33m$SwapUsedPerc\e[38;5;27m%), Total: \e[38;5;33m${SwapTotalGB}\e[38;5;27mGB" fi DiskRootTotalGB=$(jq -r ".DiskRoot.TotalGB" $ExportFile) DiskRootFreeGB=$(jq -r ".DiskRoot.FreeGB" $ExportFile) DiskRootUsedGB=$(jq -r ".DiskRoot.UsedGB" $ExportFile) DiskRootFreePerc=$(jq -r ".DiskRoot.FreePerc" $ExportFile) DiskRootUsedPerc=$(jq -r ".DiskRoot.UsedPerc" $ExportFile) if [[ -n $DiskRootTotalGB ]] && [[ "$DiskRootTotalGB" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mRoot \e[38;5;93m= \e[38;5;27mFree: \e[38;5;33m${DiskRootFreeGB}\e[38;5;27mGB (\e[38;5;33m$DiskRootFreePerc\e[38;5;27m%), Used: \e[38;5;33m${DiskRootUsedGB}\e[38;5;27mGB (\e[38;5;33m$DiskRootUsedPerc\e[38;5;27m%), Total: \e[38;5;33m${DiskRootTotalGB}\e[38;5;27mGB" fi UpdateCount=$(jq -r ".Updates.Count" $ExportFile) UpdateType=$(jq -r ".Updates.Type" $ExportFile) if [[ -n $UpdateCount ]] && [[ "$UpdateCount" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mUpdates \e[38;5;93m= \e[38;5;33m$UpdateCount\e[38;5;27m ${UpdateType} updates available" fi SessionCount=$(jq -r ".Sessions.Count" $ExportFile) if [[ -n $SessionCount ]] && [[ "$SessionCount" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mSessions \e[38;5;93m= \e[38;5;33m$SessionCount\e[38;5;27m" fi ProcessCount=$(jq -r ".Processes.Count" $ExportFile) ProcessMax=$(jq -r ".Processes.Max" $ExportFile) if [[ -n $ProcessCount ]] && [[ "$ProcessCount" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mProcesses \e[38;5;93m= \e[38;5;33m$ProcessCount\e[38;5;27m running processes of \e[38;5;33m$ProcessMax\e[38;5;27m maximum processes" fi HttpdVersion=$(jq -r ".Httpd.Version" $ExportFile) if [[ -n $HttpdVersion ]] && [[ "$HttpdVersion" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mApache \e[38;5;93m= \e[38;5;27mVersion: \e[38;5;33m$HttpdVersion" fi NginxVersion=$(jq -r ".Nginx.Version" $ExportFile) if [[ -n $NginxVersion ]] && [[ "$NginxVersion" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mnginx \e[38;5;93m= \e[38;5;27mVersion: \e[38;5;33m$NginxVersion" fi MysqlVersion=$(jq -r ".Mysql.Version" $ExportFile) MysqlDistribution=$(jq -r ".Mysql.Distribution" $ExportFile) if [[ -n $MysqlVersion ]] && [[ "$MysqlVersion" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mMySQL \e[38;5;93m= \e[38;5;27mVersion: \e[38;5;33m$MysqlVersion \e[38;5;27mDistribution: \e[38;5;33m$MysqlDistribution" fi PostgresVersion=$(jq -r ".Postgres.Version" $ExportFile) if [[ -n $PostgresVersion ]] && [[ "$PostgresVersion" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mPostgreSQL \e[38;5;93m= \e[38;5;27mVersion: \e[38;5;33m$PostgresVersion" fi PhpVersion=$(jq -r ".Php.Version" $ExportFile) PhpMaxMemory=$(jq -r ".Php.MaxMemory" $ExportFile) if [[ -n $PhpVersion ]] && [[ "$PhpVersion" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mPHP \e[38;5;93m= \e[38;5;27mVersion: \e[38;5;33m$PhpVersion, \e[38;5;27mMemory Limit: \e[38;5;33m$PhpMaxMemory" fi ElasticsearchVersion=$(jq -r ".Elasticsearch.Version" $ExportFile) if [[ -n $ElasticsearchVersion ]] && [[ "$ElasticsearchVersion" != "Unknown" ]] && [[ "$ElasticsearchVersion" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mElasticsearch \e[38;5;93m= \e[38;5;27mVersion: \e[38;5;33m$ElasticsearchVersion" fi LogstashVersion=$(jq -r ".Logstash.Version" $ExportFile) if [[ -n $LogstashVersion ]] && [[ "$LogstashVersion" != "Unknown" ]] && [[ "$LogstashVersion" != "null" ]] ; then echo -e "\e[0;38;5;17m$Fto \e[38;5;39mLogstash \e[38;5;93m= \e[38;5;27mVersion: \e[38;5;33m$LogstashVersion" fi echo -e "$BlueScheme$LongBlueScheme$BlueScheme$ShortBlueScheme\e[0;37m" } GenerateHtmlTheme () { if [[ "$HideVersion" -eq 1 ]]; then ShownVersion="" else ShownVersion="$ScriptVersion" fi # shellcheck disable=SC2162 read -d '' HtmlCode < FireMotD

System Overview - $HostName

EOF [[ $PhpVersion =~ ^[0-9.]+$ ]] && HtmlCode+=" " [[ $HttpdVersion =~ ^[0-9.]+$ ]] && HtmlCode+=" " [[ -n $NginxVersion ]] && HtmlCode+=" " [[ -n $MysqlVersion ]] && HtmlCode+=" " [[ -n $PostgresVersion ]] && HtmlCode+=" " HtmlCode+="
$HostName $ShownVersion
IP $HostIp
Operating System $Release
Kernel $Kernel
Platform $Platform
Uptime ${UptimeDays} day(s). ${UptimeHours}:${UptimeMinutes}:${UptimeSeconds}
CPU Usage ${CpuUsageAverage} average CPU usage over $CpuUsageCpuCount core(s)
CPU Load $CpuLoad
Memory Free: ${MemFreeGB}GB ($MemFreePerc%), Used: ${MemUsedGB}GB ($MemUsedPerc%), Total: ${MemTotalGB}GB
Swap Free: ${SwapFreeGB}GB ($SwapFreePerc%), Used: ${SwapUsedGB}GB ($SwapUsedPerc%), Total: ${SwapTotalGB}GB
Root Free: ${DiskRootFreeGB}GB ($DiskRootFreePerc%), Used: ${DiskRootUsedGB}GB ($DiskRootUsedPerc%), Total: ${DiskRootTotalGB}GB
Updates $UpdateCount ${UpdateType} updates available
Sessions $SessionCount
Processes $ProcessCount running processes of $ProcessMax maximum processes
PHP Info Version: $PhpVersion, Memory Limit: $PhpMaxMemory
Apache Info Version: $HttpdVersion
nginx Info Version: $NginxVersion
MySQL Info Version: $MysqlVersion, Distribution: $MysqlDistribution
PostgreSQL Info Version: $PostgresVersion
" echo "$HtmlCode" } # shellcheck disable=SC2154,SC2034 GenerateInvader () { WriteLog Verbose Info "Generating Invader Theme" f=3 b=4 for j in f b; do for i in {0..7}; do printf -v $j$i %b "\e[${!j}${i}m" done done bld=$'\e[1m' rst=$'\e[0m' HostName=$(jq -r ".HostName.Value" $ExportFile) cat << EOF $f1 ▀▄ ▄▀ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4 ▀▄ ▄▀ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst $f1 ▄█▀███▀█▄ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4 ▄█▀███▀█▄ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst $f1█▀███████▀█ $f2▀▀███▀▀███▀▀ $f3▀█▀██▀█▀ $f4█▀███████▀█ $f5▀▀███▀▀███▀▀ $f6▀█▀██▀█▀$rst $f1▀ ▀▄▄ ▄▄▀ ▀ $f2 ▀█▄ ▀▀ ▄█▀ $f3▀▄ ▄▀ $f4▀ ▀▄▄ ▄▄▀ ▀ $f5 ▀█▄ ▀▀ ▄█▀ $f6▀▄ ▄▀$rst EOF HostName=$(jq -r ".HostName.Value" $ExportFile) echo -e " $f2 Hostname: $HostName" HostIp=$(jq -r ".HostIp.Value" $ExportFile) echo -e " $f3 Ip: $HostIp" Release=$(jq -r ".Release.Value" $ExportFile) echo -e " $f4 Os: $Release" Kernel=$(jq -r ".Kernel.Value" $ExportFile) echo -e " $f5 Kernel: $Kernel" Platform=$(jq -r ".Platform.Value" $ExportFile) echo -e " $f6 Platform: $Platform" cat << EOF $bld$f1▄ ▀▄ ▄▀ ▄ $f2 ▄▄▄████▄▄▄ $f3 ▄██▄ $f4▄ ▀▄ ▄▀ ▄ $f5 ▄▄▄████▄▄▄ $f6 ▄██▄ $rst $bld$f1█▄█▀███▀█▄█ $f2███▀▀██▀▀███ $f3▄█▀██▀█▄ $f4█▄█▀███▀█▄█ $f5███▀▀██▀▀███ $f6▄█▀██▀█▄$rst $bld$f1▀█████████▀ $f2▀▀▀██▀▀██▀▀▀ $f3▀▀█▀▀█▀▀ $f4▀█████████▀ $f5▀▀▀██▀▀██▀▀▀ $f6▀▀█▀▀█▀▀$rst $bld$f1 ▄▀ ▀▄ $f2▄▄▀▀ ▀▀ ▀▀▄▄ $f3▄▀▄▀▀▄▀▄ $f4 ▄▀ ▀▄ $f5▄▄▀▀ ▀▀ ▀▀▄▄ $f6▄▀▄▀▀▄▀▄$rst EOF UptimeDays=$(jq -r ".Uptime.Days" $ExportFile) UptimeHours=$(jq -r ".Uptime.Hours" $ExportFile) UptimeMinutes=$(jq -r ".Uptime.Minutes" $ExportFile) UptimeSeconds=$(jq -r ".Uptime.Seconds" $ExportFile) echo -e " $f2 Uptime ${UptimeDays} day(s). ${UptimeHours}:${UptimeMinutes}:${UptimeSeconds}" CpuUsageAverage=$(jq -r ".CpuUsage.Average" $ExportFile) CpuUsageCpuCount=$(jq -r ".CpuUsage.CpuCount" $ExportFile) CpuUsageCoreCount=$(jq -r ".CpuUsage.CoreCount" $ExportFile) CpuUsageSocketCount=$(jq -r ".CpuUsage.SocketCount" $ExportFile) echo -e " $f3 CPU Usage: ${CpuUsageAverage} % avg over ${VCL}${CpuUsageCpuCount}${VC} cpu(s) ($CpuUsageCoreCount core(s) x $CpuUsageSocketCount socket(s))" CpuLoad=$(jq -r ".CpuLoad.Value" $ExportFile) echo -e " $f4 CPU Load: $CpuLoad" UpdateCount=$(jq -r ".Updates.Count" $ExportFile) UpdateType=$(jq -r ".Updates.Type" $ExportFile) echo -e " $f5 Updates: $UpdateCount ${UpdateType} updates available" echo -e "$f7$rst" } PrintHelp () { PrintVersion echo " Usage: $ScriptName [-v] -t $ScriptName [-v] -C ['String'] $ScriptName [-vhVs] Options: -h | --help Shows this help and exits -v | --verbose Verbose mode -d | --debug Debug mode -V | --version Shows version information and exits -t | --theme Shows MotD with chosen theme -TF | --TemplateFile