#!/bin/sh # .. vim: foldmarker=[[[,]]]:foldmethod=marker # {{ ansible_managed | comment }} # Colors definition [[[ BLACK='\033[49;30m' BLACKB='\033[49;90m' RED='\033[0;31m' REDB='\033[1;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[94;49m' MAGENTA='\033[0;35m' CYAN='\033[36;49m' WHITE='\033[0;37m' BOLD='\033[1m' RESET='\033[0m' # ]]] # Function definition [[[ ## process_info() [[[ ### Return the state of processes passed in parameters ### process_info $PROCESS_LIST_TO_MONITOR $MESSAGE process_info() { PROCESS_LIST="${1}" MSG="${2}" for PROCESS in ${PROCESS_LIST}; do MSG="${MSG}${BLACKB}+ " PRINTF_PROCESS=$(printf '%-22s' "${PROCESS}") if (ps ax | grep -v grep | grep -E "${PROCESS}" > /dev/null); then MSG="${MSG}${WHITE}${PRINTF_PROCESS}${RESET}${BLACKB}= ${GREEN}RUNNING${RESET}" else MSG="${MSG}${WHITE}${PRINTF_PROCESS}${RESET}${BLACKB}= ${REDB}NOT RUNNING${RESET}" fi done printf '%b' "${MSG}" } ## ]]] ## service_info() [[[ ### Return the listening socket ### service_info $PORT_LIST_TO_MONITOR $MESSAGE service_info() { PORT_LIST="${1}" MSG="${2}" for PORT in ${PORT_LIST}; do MSG="${MSG}\\t${BLACKB}+ " # If a port listen if (ss -lutn|grep -m1 -E ":${PORT}" > /dev/null); then # Example: "tcp/127.0.0.1:25" #MSG="${MSG}${GREEN}$(ss -lutn|grep -m1 ":${PORT}"|awk '{print $1"/"$5}')${RESET} " MSG="${MSG}${GREEN}$(ss -lutn|grep -E "${PORT}"|sort|head -n1|awk '{print $1"/"$5}')${RESET} " else # Example: "22: NOT LISTENING" MSG="${MSG}${REDB}${PORT}: NOT LISTENING${RESET} " fi done printf '%b' "${MSG}" } ## ]]] # ]]] #+++++++++++++++++++: Updates Info :+++++++++++++++++++ APT_UPGRADES_NUMBER=$(apt list --upgradable 2>/dev/null | wc --lines) # If some upgrade are availabe if [ "${APT_UPGRADES_NUMBER}" -gt 1 ]; then ## Print a header [[[ printf '%b' "${RESET}" printf "${BLACKB}%33s${RESET}" | tr ' ' - printf '%b' " ${CYAN}Updates Info${RESET} " printf "${BLACKB}%33s${RESET}" | tr ' ' - # ]]] printf '%b' "\\n${BLACKB}+ ${REDB}${APT_UPGRADES_NUMBER}${RESET} ${WHITE}pending upgrades${RESET}" printf '%b' "\\n${BLACKB}+ ${WHITE}Run '${YELLOW}apt list --upgradable${WHITE}' to see them.${RESET}" fi printf '%b' "${RESET}\\n"