Setup motd » Historie » Version 1
Jeremias Keihsler, 12.01.2017 09:52
| 1 | 1 | Jeremias Keihsler | h1. Message of the day: Banner-Message |
|---|---|---|---|
| 2 | |||
| 3 | h2. Preliminary note motd |
||
| 4 | |||
| 5 | You may find additional useful information at |
||
| 6 | * http://wiki.centos.org/TipsAndTricks/BannerFiles |
||
| 7 | |||
| 8 | h2. Setup motd |
||
| 9 | |||
| 10 | The @/etc/motd@ is a file on Unix-like systems that contains a "message of the day". |
||
| 11 | This file is just static text, therefore we recreate this file every 10 mins with updated information. |
||
| 12 | |||
| 13 | I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. |
||
| 14 | |||
| 15 | h3. add script |
||
| 16 | |||
| 17 | <pre><code class="bash"> |
||
| 18 | vim /usr/local/bin/gen_motd.sh |
||
| 19 | </code></pre> |
||
| 20 | |||
| 21 | basic example: |
||
| 22 | <pre> |
||
| 23 | #!/bin/bash |
||
| 24 | # JKE 2011-05-14 |
||
| 25 | # create /etc/motd |
||
| 26 | # to be called by /etc/cron.d/gen_motd |
||
| 27 | # |
||
| 28 | echo -e " |
||
| 29 | ******************************************************************* |
||
| 30 | * xxyyy Janus Server * |
||
| 31 | * |
||
| 32 | ======h1. * |
||
| 33 | * * |
||
| 34 | * This system is for the use of authorized users only. Usage of * |
||
| 35 | * this system will be monitored and recorded by system personnel. * |
||
| 36 | * * |
||
| 37 | * Anyone using this system expressly consents to such monitoring* |
||
| 38 | * and is advised that if such monitoring reveals possible * |
||
| 39 | * evidence of criminal activity, system personel may provide the* |
||
| 40 | * evidence from such monitoring to law enforcement officials. * |
||
| 41 | * * |
||
| 42 | ******************************************************************* |
||
| 43 | * Version = `cat /etc/centos-release` |
||
| 44 | * Kernel = `uname -r` |
||
| 45 | * Uptime = `uptime | sed 's/.*up \([^,]*\), .*/\1/'` |
||
| 46 | * Mem /free = `cat /proc/meminfo | grep MemTotal | awk {'print $2'}` kB / `cat /proc/meminfo | grep MemFree | awk {'print $2'}` kB |
||
| 47 | * Swap/free = `cat /proc/meminfo | grep SwapTotal | awk {'print $2'}` kB / `cat /proc/meminfo | grep SwapFree | awk {'print $2'}` kB |
||
| 48 | * last updt = `date` |
||
| 49 | ******************************************************************* |
||
| 50 | " > /etc/motd |
||
| 51 | </pre> |
||
| 52 | |||
| 53 | set shell-script being executeable |
||
| 54 | <pre><code class="bash"> |
||
| 55 | chmod +x /usr/local/bin/gen_motd.sh |
||
| 56 | </code></pre> |
||
| 57 | |||
| 58 | h3. add script to cron |
||
| 59 | |||
| 60 | <pre><code class="bash"> |
||
| 61 | vim /etc/cron.d/gen_motd |
||
| 62 | </code></pre> |
||
| 63 | |||
| 64 | basic example: |
||
| 65 | <pre> |
||
| 66 | # JKE 2011-05-14 |
||
| 67 | # |
||
| 68 | # min hr dom month dow user command |
||
| 69 | # - - - - - |
||
| 70 | # | | | | | |
||
| 71 | # | | | | +-day of week (0-7) sunday=0 or 7 |
||
| 72 | # | | | +---------month (1-12) |
||
| 73 | # | | +-----------------day of month (1-31) |
||
| 74 | # | +-------------------------hour (0-23) |
||
| 75 | # +-------------------------------------------------min (0-59) |
||
| 76 | # |
||
| 77 | 5,15,25,35,45,55 * * * * root /usr/local/bin/gen_motd.sh |
||
| 78 | </pre> |
||
| 79 | |||
| 80 | h2. Test |
||
| 81 | |||
| 82 | * recreate @motd@ manually |
||
| 83 | * login and check the output (you should see the motd) |
||
| 84 | <pre><code class="bash"> |
||
| 85 | /usr/local/bin/gen_motd.sh |
||
| 86 | ssh root@localhost |
||
| 87 | exit |
||
| 88 | </code></pre> |
||
| 89 | * wait minimum 10 mins |
||
| 90 | * login once more, you should have an updated output |