Skip to content

Instantly share code, notes, and snippets.

@McFateM
Last active January 26, 2021 15:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McFateM/8a81e74be780697cf8ab6e63a707052f to your computer and use it in GitHub Desktop.
Save McFateM/8a81e74be780697cf8ab6e63a707052f to your computer and use it in GitHub Desktop.
The bash script for my "server-info" command
#!/bin/bash
# Modified: Tuesday, January 26, 2021 9:10 AM
#
# This is server-into, formerly 'dynmotd'.
# This script reqiures 'figlet' and 'mdv'
#
# Park this script in /usr/local/bin and give it rwxr-xr-x (755) file protection.
# Create a symbolic link 'ln -s /usr/local/bin/server-info server' in /usr/local/bin if you like.
# Try to get the client IP address (important for debugging remotely in some cases).
OLD_SSH_CLIENT=$(cat /tmp/ssh_client_address)
if [ -z "$SSH_CLIENT" ]
then
echo "SSH_CLIENT is Unknown. Using previously obtained address."
else
echo $SSH_CLIENT | awk {'print $1'} > /tmp/ssh_client_address
fi
CLIENT_ADDRESS=$(head -n 1 /tmp/ssh_client_address)
cp -f /etc/server-info.md /tmp/server-info.md
sed -i.bak 's/'SSH_CLIENT_HERE'/'$CLIENT_ADDRESS'/g' /tmp/server-info.md
# Get some session/user info.
PROCCOUNT=`ps -Afl | wc -l`
PROCCOUNT=`expr $PROCCOUNT - 5`
GROUPZ=`groups`
if [[ $GROUPZ == *irc* ]]; then
ENDSESSION=`cat /etc/security/limits.conf | grep "@irc" | grep maxlogins | awk {'print $4'}`
PRIVLAGED="IRC Account"
else
ENDSESSION="Unlimited"
PRIVLAGED="Regular User"
fi
# Try to determine the OS and version.
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
if [ -f /etc/redhat-release ]; then
OS=$(cat /etc/centos-release)
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_DESCRIPTION
fi
# OK, go!
echo -e "\033[1;32m`hostname | figlet -f /usr/share/figlet/big.flf`"
echo -e "\033[0;35m+++++++++++++++++: \033[0;36mSystem Data\033[0;35m :+++++++++++++++++++
\033[0;35m+ \033[0;94mHostname \033[0;35m= \033[1;32m`hostname`
\033[0;35m+ \033[0;94mOS \033[0;35m= \033[1;32m`echo $OS`
\033[0;35m+ \033[0;94mAddress \033[0;35m= \033[1;32m`hostname -I`
\033[0;35m+ \033[0;94mKernel \033[0;35m= \033[1;32m`uname -r`
\033[0;35m+ \033[0;94mMemory \033[0;35m= \033[1;32m`cat /proc/meminfo | grep MemTotal | awk {'print $2'}` kB
\033[0;35m+ \033[0;94mSSH Client \033[0;35m= \033[1;32m`echo $CLIENT_ADDRESS`"
echo -e "\033[0;35m++++++++++++++++++: \033[0;36mUser Data\033[0;35m :++++++++++++++++++++
\033[0;35m+ \033[0;94mUsername \033[0;35m= \033[1;32m`whoami`
\033[0;35m+ \033[0;94mPrivlages \033[0;35m= \033[1;32m$PRIVLAGED
\033[0;35m+ \033[0;94mSessions \033[0;35m= \033[1;32m`who | grep $USER | wc -l` of $ENDSESSION MAX
\033[0;35m+ \033[0;94mProcesses \033[0;35m= \033[1;32m$PROCCOUNT of `ulimit -u` MAX"
echo -e "\033[0;35m++++++++++++++++++: \033[0;346Disk Data\033[0;35m :++++++++++++++++++++
\033[1;32m`df -h / | grep '%'`"
echo -e "\033[0;35m+++++++++++++: \033[0;36mHelpful Information\033[0;35m :+++++++++++++++
\033[0;35m+ \033[0;94mThis Script \033[0;35m= \033[1;32m/usr/local/bin/server-info
\033[0;35m+ \033[0;94mMaintenance Info \033[0;35m= \033[1;32m/etc/server-info.md
\033[0;35m+ \033[0;94mMore Information \033[0;35m= \033[1;32mhttps://static.grinnell.edu/blogs/McFateM"
echo -e "\033[0;35m+++++++++++: \033[0;31mMaintenance Information\033[0;35m :+++++++++++++
`mdv /etc/server-info.md`"
echo ""
@McFateM
Copy link
Author

McFateM commented Jan 26, 2021

Updated the "More Information" link to point to my professional blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment