See how you can customize the screen you see when you login to give you important information quickly.We can configure the Message of the Day, which is useful for displaying data to us on login. When you have a lot of servers to log into, this can be VERY handy.
The information you put here can be specific to your use case. At work, I output the customer information that's specific to the server I log into.
However we can use it to get some general information as well. Let's make a script for that. Here's the contents of a shell script I've named on_login.sh
:
#! /usr/bin/env bash
# Basic info
HOSTNAME=`uname -n`
ROOT=`df -Ph | grep xvda1 | 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'}`
echo "
===============================================
- Hostname............: $HOSTNAME
- 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
===============================================
"
Now we can use that.
Ubuntu
Ubuntu makes this pretty easy. We can simply throw the above script into the directory /etc/update-motd.d/
.
sudo mv on_login.sh /etc/update-motd.d/05-info
sudo chmod +x /etc/update-motd.d/05-info
Once you log out and back in, we'll see that info!
CentOS
CentOS takes just a little more work to setup.
- We need to turn off (yes, off) SSH's
PrintMotd
option by editing/etc/ssh/sshd_config
:
PrintMotd no
This stops printing from the plaintext /etc/motd
and lets us print our own content.
We just need to restart sshd
as so that takes affect:
sudo service sshd restart
Now we'll place our shell script into /etc/profile.d
.
sudo mv on_login.sh /etc/profile.d/login-info.sh
Then once we login, we'll see the output of our script!