Recently a friend of mine showed me the cool MotD message he set up on his Ubuntu server that displays upon ssh login; it displays useful information such as OS & kernel version, uptime, system load, memory usage and other system stats. After some searching I found a MotD generator for CentOS here; it’s made up of two scripts: count_yum_updates.sh and generate_motd.sh. As the names imply, the first script counts the number of yum updates available, whose output will be read by the second script when it creates the MotD banner. Below are the instructions I’ve adapted from the author’s site on how to install it.
Install the dependencies for the scripts:
1 |
yum install openssh-clients bc sysstat -y |
Download the scripts and make them executable:
1 2 3 |
wget https://raw.githubusercontent.com/willemdh/generate_motd/master/count_yum_updates.sh wget https://raw.githubusercontent.com/willemdh/generate_motd/master/generate_motd.sh chmod +X count_yum_updates.sh generate_motd.sh |
Test the scripts to see if they work correctly:
1 2 3 |
# generate_motd.sh looks for this file to see # of updates ./count_yum_updates.sh > /tmp/yum_updates.txt ./generate_motd.sh |
If everything works, you should see similar output to below:
Copy scripts to their final locations:
1 2 |
cp count_yum_updates.sh /usr/local/bin cp generate_motd.sh /etc/profile.d |
Make a cron job to run count_yum_updates.sh automatically (adjust for your own preferred interval):
1 2 3 |
crontab -e 0 0 * * * /usr/local/bin/count_yum_updates.sh > /tmp/yum_updates.txt |
Now you’ll get a nice MotD whenever you log in with ssh. These scripts worked perfectly fine on a CentOS droplet at Digital Ocean but at RamNode the MotD did not display the IP address of the server. I’m not sure if it was because they were OpenVZ or not but I fixed the issue by modifying line 80 of generate_motd.sh:
Original line 80:
1 |
\e[0;34m## \e[1;33mIp \e[1;34m= \e[0;32m`ip route get 8.8.8.8 | head -1 | cut -d' ' -f8` |
Modified:
1 |
\e[0;34m## \e[1;33mIp \e[1;34m= \e[0;32m`ip route get 8.8.8.8 | head -1 | cut -d' ' -f6` |