Skip to content


Configurer un "Message du jour" dynamique sous Debian Wheezy

Introduction

Qu'est-ce que le "Message du jour" en Anglais "Message of the day" : motd.

C'est une fonctionnalité qui permet lorsqu'on s'identifie en console d'afficher toutes sortes de messages !

On peut créer un message statique qui ne varie pas dans le temps ou en fonction de certains paramètres mais on peut le rendre dynamique.

Mise en place de la dynamique

Deux point à vérifier :

- une entrée de motd dynamique dans /etc/pam.d/login

grep motd /etc/pam.d/login
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session    optional   pam_motd.so  motd=/run/motd.dynamic
session    optional   pam_motd.so

- l’existence du répertoire /etc/update-motd.d/ et exécutable

if [ ! -d "/etc/update-motd.d/" ];then mkdir /etc/update-motd.d; chmod +x /etc/update-motd.d; fi

ATTENTION IMPORTANT

Il faut encore faire :

rm /etc/motd
ln -s /var/run/motd.dynamic /etc/run

Ces deux point vérifié l'ensemble est en place, il ne reste qu'a créer des scripts dans /etc/update-motd.d/ pour modifier dynamiquement le "motd".

Script de MOTD

J'ai créer deux scripts (comme on peut en trouver sur le web) :

ll /etc/update-motd.d/
total 8
-rwxr-xr-x 1 root root 1376 sept. 28 11:22 00-header
-rwxr-xr-x 1 root root 1387 sept. 28 11:14 10-sysinfo

Voici le contenu de 00-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)
printf "\n"
 
printf "Welcome to %s (%s).\n" "$DISTRIB_DESCRIPTION" "$(uname -r)"
printf "\n"

Il faut installer figlet, toilet et linux_logo ! 🙂

Voici le contenu de 10-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.
 
date=`date`
load=`cat /proc/loadavg | awk '{print $1}'`
root_usage=`df -h / | awk '/\// {print $(NF-1)}'`
memory_usage=`free -m | awk '/Mem/ { printf("%3.1f%%", $3/$2*100) }'`
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'`
users=`users | wc -w`
 
echo "System information as of: $date"
echo
printf "System load:\t%s\tMemory usage:\t%s\n" $load $memory_usage
printf "Usage on /:\t%s\tSwap usage:\t%s\n" $root_usage $swap_usage
printf "Local users:\t%s\n" $users
echo

Voilà ce que cela donne :

motd-01

Voilà !

😉

Print Friendly, PDF & Email

Posted in Debian, Linux, Technique, Toutes. Tagged with , , , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.

Time limit is exhausted. Please reload CAPTCHA.


/* */
Creative Commons License
Cette création par Laurent Besson est mise à disposition selon les termes de la licence Creative Commons Paternité-Partage des Conditions Initiales à l'Identique 2.0 France.