Skip to content
  • Home
  • Fora
    • Centos
    • InfluxDB
    • Linode
    • Nagios
    • NSClient ++
    • Raspberry Pi
    • RunDeck
  • Friends
    • Box293
    • Grafana
    • InfluxData
    • Nagios
    • NSClient++
    • Puro Themes
    • Psychologische Zorg Op Maat
    • RunDeck
  • About

OutsideIT

Monitoring and Automation to Invent Your Own Future.

  • Monitoring
    • Monitoring F5 BIG-IP Platform
    • Monitoring Infoblox DDI
    • Monitoring Linux Processes
    • Monitoring MS IIS Application Pools
    • Monitoring MS Windows Disk Load
    • Monitoring MS Windows Network Connections
    • Monitoring MS Windows Scheduled Tasks
    • Monitoring MS Windows Updates
    • Monitoring NetApp Ontap
    • Monitoring WordPress Updates
  • Reviews
    • CentOS 7
    • FOSDEM 2018
    • Rundeck 2.10
  • Tutorials
    • A+ Rating on SSLLabs
    • Cryan Syntax Highlighter Examples
    • How to Debug Perl Scripts with EPIC Eclipse
    • JSON Over TCP With Powershell
    • Real-time Eventlog Monitoring with Nagios and NSClient++
    • Realmd and SSSD Active Directory Authentication
  • Utilities
    • FireMotD

Tag: rpm

FireMotD – Dynamic MotD Generator

21 January 201821/01/2018willemdh10 Comments

Introduction

While developing, playing or working on Linux (or Windows) systems, a dynamic MotD generator script can quickly give you an overview of all used components of your Linux systems. FireMotD can show you this information in a sanitized and colorful way while you log in with SSH or console.
Over the past years I’ve been working on the ultimate MotD generator which can be tuned with themes and easily extended. Not having to manually check for available updates, check the server load or how many users are logged on can really save yourself some valuable time. Depending of the chosen theme FireMotD will output all information defined in the theme on your server.

‘Breaking News’

21/02/18 => Theme template files allow you to assemble your theme exactly like you want it. Choose your own characters, colors, separators, keys and values. I provided two new example themes, named ‘Elastic’ and ‘Eline’. Feel free to add your own customized themes with a pull request to the FireMotD project!

11/12/17 => My colleague Jarno made a Powershell version of FireMotD! It’s really awesome and allows you to show some useful information about the system you are working on. Give it a try with the following oneliner:

1
(new-object net.webclient).DownloadFile('https://raw.githubusercontent.com/OutsideIT/FireMotD/master/FireMotD.ps1','FireMotD.ps1') ; . .\FireMotD.ps1 ; Get-FireMotD

The result should look like this:

Powershell MotD

Please note that it’s a work in progress and misses some function such as the number of updates and CPU Load, but it’s definitely a nice start! Feel free to add useful things by making a pull request to the GitHub repository!

02/12/17 => I moved the FireMotD repository from https://github.com/willemdh/FireMotD to https://github.com/OutsideIT/FireMotD.  

Themes

At this moment there are 5 themes you can choose.

– Three 256 color themes: ‘Gray’, ‘Invader’, ‘Modern’, ‘Original’
– Three 16 color themes: ‘Clean’, ‘Blue’, ‘Red’
– One Html theme ‘Html’

256 Colors

Digipolis

Digipolis FireMotD Theme

ElineFireMotD Eline Theme

ElasticFireMotD Elastic Theme

Modern

FireMotD Modern

Original

FireMotD Original

Orange

FireMotD Orange

16 Colors

Blue

FireMotD Blue

Red

FireMotD Red

Gray

MotD FireMotD Gray

Html

FireMotD-Theme-Html-v5.13

Bash Colors

Most terminals are not just able to display black and white, they can also display colors thanks to escape sequences which are composed of an escape character (in Bash backslash \ ) followed by some other characters. For using one of the 256 colors on the foreground or text color, the control sequence is: \e[0;<colornumber>m
If you want to edit one of the 256 colors on the background, the control sequence is: \e]48;5<colornumber>m

FireMotD contains a nice and useful colortest:

1
FireMotD -C

FireMotD-Theme-Colortest-v5.14

And a colormap with the numbers for the control sequences:

1
FireMotD -M

FireMotD-Theme-Colortest-v5.13

You can find more information about terminals and colors here.

Terminal Emulators

It took me some time to figure out the best console emulator which supports 256 colors. With the help of some Cmder power users in this GitHub issue, I was pointed out that the development version of Cmder has an integrated mintty thanks to Babun. At the moment I’m still using this task, which launches a tab in Conemu or Cmder with a 256 color SSH session.

1
"%userprofile%\.babun\cygwin\bin\mintty.exe" /usr/bin/ssh root@server -new_console:t:server-root

An alternative to using mintty, would be to use the msys connector, created by Maximus. As Maximums points out

Running bash from mintty in ConEmu looks like running bash inside Ubuntu inside VirtualBox in Windows. Check cygwin/msys connector developed specially for ConEmu.

So I gave his msys connector a try and after some small issues and some help of Maximum, I got it working. It works fine, but still has some minor flaws imho:

  • No right-click paste
  • Weird output with some commands such as top
  • When the console windows is resized, colors get scrambled.

You need to copy the executable of the Connector into the bin folder of your cygwin installation and create a task which executes the correct Connector. Please read through this ConEmu documentation. The task I’m using with the Connector looks like this:

1
conemu-cyg-64.exe -cur_console:h0 /usr/bin/ssh user@server

How to use MotD generator?

 System Install

You need to have make installed on the system, if you want to use the Makefile.

To install to /usr/local/bin/FireMotD
1
sudo make install

With this you can probably run FireMotD from anywhere in your system. If not, you need to add /usr/local/bin to your$PATH variable. To adjust the installation path, change the var IDIR=/usr/local/bin in the Makefile to the path you want.

To install bash autocompletion support
1
sudo make bash_completion

With this you can use TAB to autocomplete parameters and options with FireMotD. Does not require the sudo make install above (system install), but requires the bash-completion package to be installed and working. Then you should logout-login or source the bash completion file, eg. $ . /etc/bash_completion.d/FireMotD

If you don’t have root access, just install everything on your user’s folder and source the file from your user’s .profile file

Crontab to get system information

This is an example on how to record the system update package count daily. This will update the file /var/tmp/FireMotD.json for later access. Root privilege is required for this operation.

To edit root’s crontab
1
sudo crontab -e
Then add this line (updates everyday at 3:03am)
1
3 3 * * * /usr/local/bin/FireMotD -S > /dev/null
Or using the old way
1
3 3 * * * /usr/local/bin/FireMotD -U > /var/tmp/updatecount.txt

Adding FireMotD to run on login

Choosing where to run your script is kind of situational. Some files will only run on remote logins, other local logins, or even both. You should find out what suits best your needs on each case.

To add FireMotD to a single user

Edit the user’s ~/.profile  file, ~/.bash_profile  file, or the ~/.bashrc  file

1
nano ~/.profile

Add the FireMotD call at the end of the file (choose your theme)

1
/usr/local/bin/FireMotD -t red
To add FireMotD to all users

You may call FireMotD from a few different locations for running globally.
Eg / etc/bash.bashrc and   /etc/profile .

You may also create a initialization script, for example init.sh  which will call the FireMotD script in /etc/profile.d  when logging in. You can put whatever you like in this init.sh script. Everything in it will be executed at the moment someone logs in your system. Example:

1
2
#!/bin/bash
/usr/local/bin/FireMotD --Theme Red

MotD Generator Components

Script Version

To make it easy to see what version of generate_motd.sh you are using, I integrated the version in the frame of the MotD.

1
2
ScriptName="`readlink -e $0`"
ScriptVersion=" `cat $ScriptName | grep "# Version:" | awk {'print $3'} | tr -cd '[[:digit:].-]' | sed 's/.\{2\}$//'` "

Ip

I changed the method of retrieving the ip address. As CentOS 7 has different naming conventions, it seem a more solid method to use ip route.

1
ip route get 8.8.8.8 | head -1 | cut -d' ' -f8

Release

It’s always useful to know what Linux release your are working on.

1
cat /etc/*release | head -n 1

Kernel

Knowing the exact kernel version can also contribute to learning to know your servers

1
uname -rs

Uptime

I found this command to be working best on most systems. It is also capable of showing the number of days, hours, minutes and seconds. I also found it more useful then just using ‘uptime‘.

1
awk '{print int($1/86400)" day(s) "int($1%86400/3600)":"int(($1%3600)/60)":"int($1%60)}' /proc/uptime

Average CPU Utilization

CPU utilization is a little harder as you prefer to get the average CPU utilization. To achieve this I’m using mpstat.

1
CpuUtil=`LANG=en_GB.UTF-8 mpstat 1 1 | awk '$2 ~ /CPU/ { for(i=1;i<=NF;i++) { if ($i ~ /%idle/) field=i } } $2 ~ /all/ { print 100 - $field}' | tail -1`

I also prefer to see the number of cores in the output:

1
CpuProc="`cat /proc/cpuinfo | grep processor | wc -l` core(s)."

Detect virtualization technique or hardware platform

‘dmesg’ is a command on most Unix-like operating systems that prints the message buffer of the kernel. It’s a useful command for the MotD generator as it doesn’t require any special permissions.

  • Qemu with KVM

    1
    2
    Platform=`dmesg | grep "DMI:" | sed 's/^.*QEMU/QEMU/' | sed 's/, B.*//'`
     

  • VMware

    1
    Platform=`dmesg | grep "DMI:" | sed 's/^.*VMware/VMware/' | sed 's/, B.*//'`

  • Fujitsu Primergy

    1
    Platform=`dmesg | grep "DMI:" | sed 's/^.*FUJITSU PRIMERGY/Fujitsu Primergy/' | sed 's/, B.*//'`

On some systems, you could get an ‘Unknown’ result. Please let me know on GitHub by making an issue. You should be able to find the correct platform with dmesg, cut and sed.

Cowsay and other ASCII generators

Something old school that exists for a really long time is Cowsay, which is a configurable speaking ASCII cow. I’ve seen several people integrate it in their MotD, but personally I think it does not fit into an enterprise. Something to play with at home though. You can even make it say a random expression every time you log in. Here you can find an implementation of Cowsay where you can output to html, text or even Json. And here you can find a Python implmentation of Cowsay. I also stumbled on Christopher Johnson’s ASCII Art Collection , an ascii archive containing a massive amount of ASCII art examples. The website is kind of outdated, but check it out if you like ascii art or if you are looking for something to integrate into your MotD. If you want convert some text to ASCII, check out this website or this one where you can enter some text, choose a font, character width and height and see the result immediately. If you want to convert an image to ASCII, check out this website.

(Almost) Final words

It might seem like a small tool, but my MotD generator can really help you get a quick overview of your Linux server state. I’ll try to extend the tool when I find the time, as I still have some ideas left which can improve it. Let me know on the Nagios Exchange what you think of my plugin by rating it or submitting a review. Please also consider starring the project on GitHub.

The last releases are a little slower, as querying the PHP, Apache and MariaDB versions take some time. In future releases, this info will be gathered with a cron job, a bit like the yum update count. Feel free to comment unneeded code to speed things up.
 
Thanks to all contributors to FireMotD!
 

Tags

automation backup Bash CentOS Centos 7 cluster cpu disk elasticsearch eventlog filter Linux Logstash memory Microsoft monitoring Nagios Nagios XI netapp NRPE NSClient++ parameters pending updates perfmon performance performance counter Powershell process Raspbian Red Hat RunDeck script scripting security Shell snapshot SSL syntax system threshold updates web application Windows Windows Server yum
© 2018 OutsideIT - Theme by Puro