Last active
November 11, 2021 15:02
-
-
Save fishi0x01/417de50e68d4b8d0f6f1 to your computer and use it in GitHub Desktop.
Dynamic login messages with update-motd framework. Code for blog post https://fishi.devtail.io/weblog/2015/02/06/dyamic-login-messages-update-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
# Simple static header for update-motd framework | |
COLOR_GREEN="\033[0;32m" | |
# print personal static banner in green | |
printf "${COLOR_GREEN} | |
_____ .__ .__ .__ | |
_/ ____\|__| ______| |__ |__| | |
\ __\ | | / ___/| | \ | | | |
| | | | \___ \ | Y \| | | |
|__| |__|/____ >|___| /|__| | |
\/ \/ | |
Debian GNU/Linux 7.x\n\n" |
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
# Simple dynamic quote header for update-motd framework | |
COLOR_BLUE="\033[01;34m" | |
COLOR_DEFAULT="\033[0m" | |
# print a random session quote | |
printf "${COLOR_BLUE}Session Quote:\n" | |
/usr/games/fortune 100% computers | /usr/games/cowsay -f tux | |
# reset color to terminal default | |
printf "${COLOR_DEFAULT}\n" |
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
# Simple system performance counter retriever | |
# current date | |
date=`date` | |
# current cpu load | |
cpu_load=`cat /proc/loadavg | awk '{print $1*100 "%"}'` | |
# used memory | |
memory_usage=`free -m | awk '($1=="Mem:"){memTotal=$2} ($2=="buffers/cache:"){memUsed=$3} END{printf "%.1f%%", memUsed/memTotal * 100}'` | |
# used swap memory | |
swap_usage=`free -m | awk '($1=="Swap:"){swapTotal=$2; swapUsed=$3} END{printf "%.1f%%", swapUsed/swapTotal * 100}'` | |
# used disk space | |
disk_usage=`df -h | awk '{if($(NF) == "/") {print $(NF-1); exit;}}'` | |
# number of open user sessions | |
user_sessions=`users | wc -l` | |
# system uptime | |
sys_uptime=`uptime | awk '{print $3 " " $4}' | sed s'/.$//'` | |
# running processes | |
running_processes=`ps aux | wc -l` | |
# machine's IP address | |
used_ip=`ifconfig eth0 | grep "inet addr" | awk -F ":" '{print $2}' | awk '{print $1}'` | |
COLOR_DEFAULT="\033[0m" | |
COLOR_INFO="\033[0;37m" | |
COLOR_VALUE="\033[0;35m" | |
printf "${COLOR_INFO}System Information on ${date}\n" | |
printf "==================================================\n" | |
printf "${COLOR_INFO}CPU Usage :${COLOR_VALUE} %s\n" "${cpu_load}" | |
printf "${COLOR_INFO}Memory Usage :${COLOR_VALUE} %s\n" "${memory_usage}" | |
printf "${COLOR_INFO}Swap Usage :${COLOR_VALUE} %s\n" "${swap_usage}" | |
printf "${COLOR_INFO}System Uptime :${COLOR_VALUE} %s\n" "${sys_uptime}" | |
printf "${COLOR_INFO}IP Address :${COLOR_VALUE} %s\n" "${used_ip}" | |
printf "${COLOR_INFO}Total Disk Usage :${COLOR_VALUE} %s\n" "${disk_usage}" | |
printf "${COLOR_INFO}Open Sessions :${COLOR_VALUE} %s\n" "${user_sessions}" | |
printf "${COLOR_INFO}Running Processes :${COLOR_VALUE} %s\n" "${running_processes}" | |
printf "${COLOR_DEFAULT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment