#! /bin/bash # motd.sh # A basic motd script with some nice information. Designed to be extensible # and easily configurable per-host # NOTE: We do not set -e here because we don't want MOTD generation to fail # in the event that just this script fails # Services that we want a quick heads-up on their status declare -a services {% for item in (motd_watch_services + motd_watch_services_extra)|sort %} services+=("{{ item }}") {% endfor %} ## Now, we actually put this info to use # Starting with services if [ -n "${services[*]}" ]; then printf "\e[1mService Statuses\e[0m\n" len=20 for service in "${services[@]}"; do status="\e[33mUnknown\e[0m" systemctl status "$service" > /dev/null 2>&1 case $? in 0) status="\e[1;32mRunning\e[0m" ;; 1|2) status="\e[1;31mDead\e[0m" ;; 3) status="\e[37mNot Running\e[0m" ;; 4) continue ;; esac printf " * \e[37m%-${len}.${len}s\e[0m - $status " "$service" if systemctl is-failed --quiet "$service"; then printf "\e[1;31m(FAILED!)\e[0m " fi printf "\n" done fi ## And some generic system status stuff printf "\e[1mSystem Status\e[0m\n" if [ -f /var/run/reboot-required ]; then printf " * \e[1;33mReboot required\e[0m\n" else printf "\e[37m - No outstanding reboots\e[0m\n" fi