Last active
December 12, 2024 13:51
-
-
Save cha55son/6042560 to your computer and use it in GitHub Desktop.
RHEL (Centos/Fedora) dynamic motd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Installation: | |
# | |
# 1. vim /etc/ssh/sshd_config | |
# PrintMotd no | |
# | |
# 2. vim /etc/pam.d/login | |
# # session optional pam_motd.so | |
# | |
# 3. vim /etc/profile | |
# /usr/local/bin/dynmotd # Place at the bottom | |
# | |
# 4. Then of course drop this file at | |
# /usr/local/bin/dynmotd | |
# | |
USER=`whoami` | |
HOSTNAME=`uname -n` | |
ROOT=`df -Ph | grep root | awk '{print $4}' | tr -d '\n'` | |
HOME=`df -Ph | grep home | awk '{print $4}' | tr -d '\n'` | |
BACKUP=`df -Ph | grep backup | awk '{print $4}' | tr -d '\n'` | |
MEMORY1=`free -t -m | grep "buffers/cache" | awk '{print $3" MB";}'` | |
MEMORY2=`free -t -m | grep "Mem" | awk '{print $2" MB";}'` | |
PSA=`ps -Afl | wc -l` | |
# time of day | |
HOUR=$(date +"%H") | |
if [ $HOUR -lt 12 -a $HOUR -ge 0 ] | |
then TIME="morning" | |
elif [ $HOUR -lt 17 -a $HOUR -ge 12 ] | |
then TIME="afternoon" | |
else | |
TIME="evening" | |
fi | |
#System uptime | |
uptime=`cat /proc/uptime | cut -f1 -d.` | |
upDays=$((uptime/60/60/24)) | |
upHours=$((uptime/60/60%24)) | |
upMins=$((uptime/60%60)) | |
upSecs=$((uptime%60)) | |
#System load | |
LOAD1=`cat /proc/loadavg | awk {'print $1'}` | |
LOAD5=`cat /proc/loadavg | awk {'print $2'}` | |
LOAD15=`cat /proc/loadavg | awk {'print $3'}` | |
echo " | |
_______ __ __ _______ _______ _______ __ _ _______ __ __ _______ _______ _______ _______ | |
| || | | || _ || || || | | || || | | || || _ || || | | |
| || |_| || |_| || _____|| _ || |_| || || |_| || _ || |_| ||_ _|| ___| | |
| || || || |_____ | | | || || || || | | || | | | | |___ | |
| _|| || ||_____ || |_| || _ || _|| || |_| || | | | | ___| | |
| |_ | _ || _ | _____| || || | | || |_ | _ || || _ | | | | |___ | |
|_______||__| |__||__| |__||_______||_______||_| |__||_______||__| |__||_______||__| |__| |___| |_______| | |
Good $TIME $USER" | |
echo " | |
=========================================================================== | |
- Hostname............: $HOSTNAME | |
- Release.............: `cat /etc/redhat-release` | |
- Users...............: Currently `users | wc -w` user(s) logged on | |
=========================================================================== | |
- Current user........: $USER | |
- 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 | |
- Processes...........: $PSA running | |
- System uptime.......: $upDays days $upHours hours $upMins minutes $upSecs seconds | |
- Disk space ROOT.....: $ROOT remaining | |
- Disk space HOME.....: $HOME remaining | |
- Disk space BACK.....: $BACKUP remaining | |
=========================================================================== | |
" |
Added colours and fortune+cowsay messages.
https://gist.github.com/knotman90/1daba2d757e2fc29b403dc4fe958f2fc
Kudos for the scripts itself, I did use it too!
But there is now a better way to run it on Centos 7 than using /etc/profile
, which has a side effect that it will run also when you do sudo su -
- please see https://github.com/gdubicki/centos-pam-with-update-motd for more info.
Added temperature and edited "Disk space" sections.
Note: Currently Fedora is do not use the /usr/local/bin
https://gist.github.com/rojenzaman/a020cfbbc2f46390a69c4631a1a76013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @cha55son,
Line 21
MEMORY1=free -t -m | grep "buffers/cache" | awk '{print $3" MB";}'
returns empty result centos...
Could you replace it with something similar to:
MEMORY1=free -t -m | grep "Mem" | awk '{print $3" MB";}'
or maybe something better because I am a newbie in Linux!
EDIT2: https://gist.github.com/themegabyte/565fac4d65219f714897