RHEL-Centos-Fedora Dynamic Motd

#!/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
===========================================================================
"
#!/bin/sh
#We need to install figlet pkg. This will be our cool formated text. From “FIGlet” is a program for making large letters out of ordinary text.
#http://pkgs.repoforge.org/figlet/
#rpm -ivh  
#
#Create a file called dymotd.sh, or whatever you wish
#touch /usr/src/scripts/dymotd
#
#Give permissions to execution
#chmod +x /usr/src/scripts/dymotd
#
#Put the absolute path(/usr/src/scripts/dymotd) at the end of the /etc/profile
[ -r /etc/lsb-release ] && . /etc/lsb-release
 
if [ -z "$DISTRIB_DESCRIPTION" ] && [ -x /usr/bin/lsb_release ]; then
        # Fall back to using the very slow lsb_release utility
        DISTRIB_DESCRIPTION=$(lsb_release -s -d)
fi
 
figlet $(hostname)
printf "\n"
 
printf "Welcome to %s (%s).\n" "$DISTRIB_DESCRIPTION" "$(uname -r)"
printf "\n"
 
#System date
date=`date`
 
#System load
LOAD1=`cat /proc/loadavg | awk {'print $1'}`
LOAD5=`cat /proc/loadavg | awk {'print $2'}`
LOAD15=`cat /proc/loadavg | awk {'print $3'}`
 
#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))
 
#Root fs info
root_usage=`df -h / | awk '/\// {print $4}'|grep -v "^$"`
fsperm=$(mount | grep root | awk '{print $6}' | awk -F"," '{print $1}')
 
#Memory Usage
memory_usage=`free -m | awk '/Mem:/ { total=$2 } /buffers\/cache/ { used=$3 } END { printf("%3.1f%%", used/total*100)}'`
swap_usage=`free -m | awk '/Swap/ { printf("%3.1f%%", $3/$2*100) }'`
 
#Users
users=`users | wc -w`
USER=`whoami`
 
#Processes
processes=`ps aux | wc -l`
 
#Interfaces
INTERFACE=$(ip -4 ad | grep 'state UP' | awk -F ":" '!/^[0-9]*: ?lo/ {print $2}')
 
echo "System information as of: $date"
echo
printf "System Load:\t%s %s %s\tSystem Uptime:\t\t%s "days" %s "hours" %s "min" %s "sec"\n" $LOAD1, $LOAD5, $LOAD15 $upDays $upHours $upMins $upSecs
printf "Memory Usage:\t%s\t\t\tSwap Usage:\t\t%s\n" $memory_usage $swap_usage
printf "Usage On /:\t%s\t\t\tAccess Rights on /:\t%s\n" $root_usage $fsperm
printf "Local Users:\t%s\t\t\tWhoami:\t\t\t%s\n" $users $USER
printf "Processes:\t%s\t\t\t\n" $processes
printf "\n"
printf "Interface\tMAC Address\t\tIP Address\t\n"
 
for x in $INTERFACE
do
        MAC=$(ip ad show dev $x |grep link/ether |awk '{print $2}')
        IP=$(ip ad show dev $x |grep -v inet6 | grep inet|awk '{print $2}')
        printf  $x"\t\t"$MAC"\t"$IP"\t\n"
 
done
echo
echo

你可能感兴趣的:(/etc/issue,/etc/motd)