Projekt

Allgemein

Profil

Setup motd » Historie » Version 2

Jeremias Keihsler, 29.07.2021 09:01

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