Dynamic MOTD

Aus Root-Wiki
Wechseln zu: Navigation, Suche

Hier eine kurze Beschreibung, wie man eine dynamische motd erstellt.

Schritte

figlet installieren, damit der Servername "schön" angezeigt wird.

apt-get install figlet

update-motd.d Verzeichnis in /etc erstellen, falls er noch nicht vorhanden ist.

mkdir /etc/update-motd.d/


Danach müssen die 2 Dateien noch befüllt werden. Der Inhalt der Dateien steht am Ende des Beitrages.

nano /etc/update-motd.d/20-header
nano /etc/update-motd.d/30-sysinfo

Alle 3 Dateien ausführbar machen.

chmod +x /etc/update-motd.d/*
Warning.png Warnung: Die beiden nachfolgenden Schritte sind bei Debian 6 nicht nötig, da die Verknüpfung meistens schon vorhanden ist. Zu Not mit "ls -la /etc/motd" prüfen.

Alte motd Datei zur Sicherheit umbenennen

mv /etc/motd /etc/motd.bak

Verknüpfung zu der dynamischen motd erstellen.

ln -s /var/run/motd /etc/motd

Ergebnis

Dynamic-motd.png

In dem Beispiel wird nicht der Servername angezeigt, sondern "...NevaKee.de...".


Datei: 20-header

#!/bin/sh
#
#    00-header - create the header of the MOTD
#    Copyright (c) 2013 Nick Charlton
#    Copyright (c) 2009-2010 Canonical Ltd.
#
#    Authors: Nick Charlton <hello@nickcharlton.net>
#             Dustin Kirkland <kirkland@canonical.com>
#
#    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 2 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, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

[ -r /etc/lsb-release ] && . /etc/lsb-release

if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
        # Fall back to using the very slow lsb_release utility
        DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi

figlet $(hostname)
#figlet ...NevaKee.de..

#printf "\n"
#printf "Welcome to %s (%s).\n" "$DISTRIB_DESCRIPTION" "$(uname -r)"
#printf "\n"

Datei: 30-sysinfo

#!/bin/bash
#
#    10-sysinfo - generate the system information
#    Copyright (c) 2013 Nick Charlton
#
#    Authors: Nick Charlton <hello@nickcharlton.net>
#
#    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 2 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, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

cpuallusage=`ps aux | awk {'sum+=$3;print sum'} | tail -n 1 | awk '{printf "%.0f\n", $1}'`
cpucores=`cat /proc/cpuinfo | grep "model name" | wc -l`
cpuusage=$((cpuallusage / cpucores)) 

# \033[0;34m+     \033[0;37mCPU usage \033[0;34m= \033[1;32m$cpuusage%

echo -e "\033[0;34m+++++++++++++++++: \033[0;37mSystem Data\033[0;34m :+++++++++++++++++++++++++++++
\033[0;34m+ \033[0;37mDate and Time \033[0;34m= \033[1;32m`date`
\033[0;34m+        \033[0;37mKernel \033[0;34m= \033[1;32m`uname -r`
\033[0;34m+        \033[0;37mUptime \033[0;34m= \033[1;32m`uptime | grep -ohe 'up .*' | sed 's/,//g' | awk '{ printf $2" "$3 }'`
\033[0;34m+          \033[0;37mLoad \033[0;34m= \033[1;32m`cat /proc/loadavg | awk '{print $1}'` `cat /proc/loadavg | awk '{print $2}'` `cat  /proc/loadavg | awk '{print $3}'`
\033[0;34m+     \033[0;37mCPU model \033[0;34m= \033[1;32m$cpucores x `cat /proc/cpuinfo | grep -m 1 "model name" | awk -F ": " '{print $2}'`
\033[0;34m+        \033[0;37mMemory \033[0;34m= \033[1;32mUsed `free -m | head -n 2 | tail -n 1 | awk {'print $3'}` MB out of `free -m | head -n 2 | tail -n 1 | awk {'print $2'}` MB
\033[0;34m+           \033[0;37mHDD \033[0;34m= \033[1;32mUsed `df -h / | tail -n 1 | awk {'print $3'}` out of `df -h / | tail -n 1 | awk {'print $2'}`
\033[0;34m+     \033[0;37mProcesses \033[0;34m= \033[1;32m`ps aux | wc -l` of `ulimit -u` MAX
\033[0;34m+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\033[0;37m
"