Skip to content

Instantly share code, notes, and snippets.

@Deltachaos
Created Mar 24, 2012
Embed
What would you like to do?
MOTD of XTAIN servers
#!/bin/bash
VERSION=0.0.2
LANG=C
HOSTNAME=`uname -n`
KERNEL=`uname -r`
CPU=`uname -p`
CPUS=$(cat /proc/cpuinfo | sed -nr 's/^model name[[:space:]]+:[[:space:]]+(.*)/\1/p')
ARCH=`uname -m`
DATE=`date`
UPTIME=`uptime`
UPTIME=${UPTIME%%,*}
UPTIME=${UPTIME##*up\ }
PROCESSESCOUNT=`ps -A | wc -l`
LOGNAMECOUNT=`who | wc -l`
LOAD=$(uptime | sed -e 's/.*,.*\: \(.*\)/\1/')
#MEMA_xxx is Memory including Buffers and Cache
MEM_RAW=$(free | sed -n -e '2p')
MEM_TOTAL=$(echo $MEM_RAW | cut -d' ' -f 2)
MEM_USED=$(echo $MEM_RAW | cut -d' ' -f 3)
#MEM_FREE=$(echo $MEM_RAW | cut -d' ' -f 4)
MEM_BUFFERS=$(echo $MEM_RAW | cut -d' ' -f 6)
MEM_CACHED=$(echo $MEM_RAW | cut -d' ' -f 7)
if [ $MEM_TOTAL -eq 0 -o $MEM_USED -eq 0 ]; then
MEMORYA_USAGE=0
MEMORYWO_USAGE=0
else
MEMORYA_USAGE=$(echo "100/${MEM_TOTAL}*${MEM_USED}" | bc -l | awk '$1 {printf "%.2f", $1}')
MEMORYWO_USAGE=$(echo "100/${MEM_TOTAL}*(${MEM_USED}-${MEM_BUFFERS}-${MEM_CACHED})" | bc -l | awk '$1 {printf "%.2f", $1}')
fi
SWAP_RAW=$(free | sed -n -e '4p')
SWAP_TOTAL=$(echo ${SWAP_RAW} | cut -d' ' -f 2)
SWAP_USED=$(echo ${SWAP_RAW} | cut -d' ' -f 3)
if [ $SWAP_TOTAL -eq 0 -o $SWAP_USED -eq 0 ]; then
SWAP_USAGE=0
else
SWAP_USAGE=$(echo "100/${SWAP_TOTAL}*${SWAP_USED}" | bc -l | awk '$1 {printf "%.2f", $1}')
fi
LSB_BIN=$(which lsb_release 2> /dev/null || which lsb-release 2> /dev/null)
if [ "${LSB_BIN}" ]; then
DISTRIB_DESCRIPTION=$(${LSB_BIN} -d | sed -r 's/(.*):[[:space:]]+(.*)/\2/')
DISTRIB_RELEASE=$(${LSB_BIN} -r | sed -r 's/(.*):[[:space:]]+(.*)/\2/')
fi
if [ -z "${DISTRIB_DESCRIPTION}" ]; then
DISTRIB_DESCRIPTION=$(uname -o)
DISTRIB_RELEASE=$(uname -v)
fi
echo -e ""
echo -e " Welcome user $USER to $HOSTNAME"
echo -e ""
[ $(id -u) -eq 0 ] && echo -e " You are root, be careful :)"
echo -e ""
echo -e " This server is running "${DISTRIB_DESCRIPTION}" in Version "${DISTRIB_RELEASE}
echo -e ""
#echo -e "========== System Information =========="
#echo -e "This server is running Debian."
echo -e " Kernel:\t\t$KERNEL\tSystem load:\t\t$LOAD"
echo -e " Architecture:\t\t$ARCH\t\tProcesses:\t\t$PROCESSESCOUNT"
echo -e " Users logged in:\t$LOGNAMECOUNT\t\tUptime:\t\t\t$UPTIME"
echo -e " Server Time:\t\t$DATE"
while read cpu; do
echo -e " CPU:\t\t\t${cpu}"
done <<EOF
${CPUS}
EOF
echo -e " => Memory"
echo -e " Memory usage (included buffer/cache): ${MEMORYA_USAGE} %"
echo -e " Memory usage (excluded buffer/cache): ${MEMORYWO_USAGE} %"
echo -e " Swap usage:\t${SWAP_USAGE} %"
if [ -f /sys/kernel/mm/ksm/run -a $(cat /sys/kernel/mm/ksm/run) -eq 1 ]; then
echo -e " => Kernel Samepage Merging (KSM):"
KSM_PAGES_SHARED=$(cat /sys/kernel/mm/ksm/pages_shared)
KSM_PAGES_FULL_SCANS=$(cat /sys/kernel/mm/ksm/full_scans)
echo -e " How many shared pages are being used:\t\t\t\t$((${KSM_PAGES_SHARED} * $(getconf PAGESIZE) / 1024 / 1024 )) MiB"
echo -e " KSM Full scans:\t$(cat /sys/kernel/mm/ksm/full_scans)"
echo -e " How many more sites are sharing them i.e. how much saved:\t$((${KSM_PAGES_SHARED} * $(getconf PAGESIZE) / 1024 / 1024 )) MiB"
fi
SCREENS=$(/usr/bin/screen -ls | sed -e '1d' | sed -e '1d' -e '$d')
if [ "${SCREENS}" ]; then
echo -e "\n => Screens"
cat <<EOF
${SCREENS}
EOF
fi;
echo -e "\n => Disk Usage"
df -hl | sed -e 's/^\(.*\)$/ \0/'
echo -e "\n => Currently logged in users (who)"
who | sed -e 's/^\(.*\)$/ \0/'
echo -e "\n => Currently logged in users and their doings (w)"
w -h | sed -e 's/^\(.*\)$/ \0/'
echo -e "\n => Your last login (last)"
#echo -e "$(lastlog -u ${LOGNAME} | sed -e '1d' )"
last -a -F -i | grep -i "^${LOGNAME}" | sed -n -e '2p' | sed -e 's/^\(.*\)$/ \0/'
echo -e "\n => Last 5 logins (last)"
last -10 -a -F -i | sed -n -e '2,6p' | sed -e 's/^\(.*\)$/ \0/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment