How to Customize Login Message in Linux with System Status Info

Changing the login message for your Linux Server is very useful in many ways. You can display many things that are helpful to someone who is logging in for the first time or users that have logged in many times and login frequently. In this post, I'll show you how to change the login message to show some very useful information (Specifically for CentOS 7, will vary by flavor of Linux). For example, you could include things like:
  • Environment (Production, Staging, etc)
  • Description (What the server does)
  • Classification (What is the level of clearance needed on the server)
  • Server Name (What Server you logged into)
  • Script Name (What script contains the log information, in case you have access and want to change it.)
  • Notify (Who to notify regarding this server)(/li)
  • Disk Space (How much disk space you have (i.e. Remaining, Total, etc)
  • CPU Usage (How busy has the CPU been over a given period of time)
  • Memory Used (How much memory is currently being used)
  • Swap Space (How much overusage of memory do you have)
You could even include the weather, if you wanted! Using curl http://wttr.in/ (Which would give you a 3 day weather report based on the location of the server). In most Linux Distros (i.e. Ubuntu, Red Hat, CentOs, etc.) you can create a custom.sh bash script in /etc/profile.d directory. Here's the code that does all the things we listed above:
#!/bin/bash
# Basic info
HOSTNAME=`uname -n`
ROOT=`df -Ph | grep /dev/simfs | awk '{print $4}' | tr -d '\n'`

# System load
MEMORY1=`free -t -m | grep Total | awk '{print $3" MB";}'`
MEMORY2=`free -t -m | grep "Mem" | awk '{print $2" MB";}'`
LOAD1=`cat /proc/loadavg | awk {'print $1'}`
LOAD5=`cat /proc/loadavg | awk {'print $2'}`
LOAD15=`cat /proc/loadavg | awk {'print $3'}`
SCRIPTNAME="custom.sh"
SCRIPTPATH="/etc/profile.d"
echo "
| Environment.....: Production
| Description.....: Acme Corporation - Edge 3 Super Computer
| Classification..: Top Secret - Level 10 Clearance
| Hostname........: $HOSTNAME
| Script Source...: $SCRIPTPATH/$SCRIPTNAME   
| Notify..........: thomas.j.watson@bio-eng-lvl10.com
=============================================================
- Disk Space.............: $ROOT remaining
- CPU usage..............: $LOAD1, $LOAD5, $LOAD15 (1, 5, 15 min)
- Memory used............: $MEMORY1 / $MEMORY2
- Swap in use............: `free -m | tail -n 1 | awk '{print $3}'` MB
=============================================================
View  /admin/README for details specific to this host
"
Hope you found this useful! Keep checking back here for more useful technical tips for total geeks like me!

Comments

  1. In conclusion, to gamble like a man, all that's required is that you just act like a man. Dress and behave like one, and you'll be be} treated like one by others and by the game. Indeed, every recreation has its own rules, and we will get to them in time, however for now, play by the foundations I have have} given you, and you'll be be} all right. I recognize that 1xbet korea this might sound slightly robotic of me, however this is for the dealer’s sake. I recognize you simply were totally bluffing about your straight flush and got the other man to fold.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Create a Symbolic Link in Unix (aka Shortcut)

Quickly Load Very Large Data Sets into Your MariaDB Database