A while ago, I wrote about some fun things to do to help secure your servers. Among the things I included was information about SSH banners, and Message of the Day files. At the time, I was not able to generate dynamic content for the Message of the day. Recently, I learned how to accomplish dynamic content on CentOS/Redhat based Linux systems. My goals for this project was to show the following:
System Information
User Information
Weather and Fortune
System Name
Warnings and Rules
MOTD Script
System Information
The system Information, I wanted to show is the following:
Hostname
Version of Linux
CPU Usage
Memory Information
Processes Running
Uptime
Disk Usage
Number of Available Updates
my motd script uses the following code to capture this information:
Hostname
Version of Linux
CPU Usage Capture the Information in variables:
Display it like this:
LOAD1 - One Minute Load
LOAD2 - Five Minute Load
LOAD3 - Fifteen Minute Load
Memory Information
To get the memory Information I do the following:
Display it like this:
$MEMORY1 - Memory Used
$MEMORY2 - Total Memory
Processes Running
To get the number of processes running I use the following:
Display it like this:
PSA - Number of running Processes
Uptime
To get system uptime I do the following:
Display it like this:
upDays - Number of days up
upHours - Number of Hours up less Days
upMins - Number of Minutes up less Days and Hours
upSecs - Number of Seconds up less Days, Hoursm and Minutes
Disk Usage
To get the disk usage I do the following:
Display it like this:
DISKC - Total amount of storage
DISKU - Amount of used storage
DISKP - Percent of disk used
Number of updates Available
The previous commands were all built into the operating system. For updates, I could have used a yum command to poll the updates everytime a login occurs, but that would have meant waiting 2-5 minutes after logging in to get a prompt. I decided to run the command to check for updates daily, and then save the results for use in logins. Because of that I have a checkupdates.sh script.
checkupdates.sh
I have a cron job:
I use the following code in the motd script to get the contents of the updates.txt file
Display it like this:
User Information
The user information I wanted to show was:
Number of Users Logged in
The logged in User
Number of Users Logged In
I show the number of users logged in like this:
User Logged In As
I show the logged in user with the following command:
Weather and Fortune
I get and display the weather with this command:
For fortune, I want shorter fortunes, and I want topics relevant to Linux, Computers, Programming, etc.
System Name
I have a section of my script, which I generate using toilet, which has the system name I’m using. I generate it, and save it to my motd script, and add echo commands. This is my first step in creating my motd file. I used another system to generate this, because there is not a CentOS package for Toilet.
Warnings and Rules
I always add a message about access permissions to my SSH Banners, and to my motd scripts. In the motd file I add a smaller message, because the SSH Banner includes a much larger message.
Complete Script
Below is my complete motd script I have included the color escape codes I use to colorize my motd script. I have removed them in the above code examples for readability.
Here is my complete motd script:
This script would not have been possible without the following pages I found as I was working on this. You will find Ideas, and text from all of these have been incorporated into what I wrote.