Created
September 22, 2020 19:31
-
-
Save mbrowniebytes/e1a6c2b3bf56e71bb0fa2b636af1c38b to your computer and use it in GitHub Desktop.
simple bash login stats
This file contains 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 | |
# display motd on login, or sudo su - user as that is a login | |
# sudo vim /etc/profile.d/login_stats.sh | |
motd(){ | |
SERVER="server-name - aws ec2" | |
# 15:52:46 up 13 days, 5:27, 1 user, load average: 0.00, 0.00, 0.00 | |
UPTIME=`uptime` | |
# trim spaces | |
UPTIME=`echo $UPTIME` | |
# total used free shared buff/cache available | |
# Mem: 7.6G 206M 5.1G 32M 2.3G 7.1G | |
# Swap: 0B 0B 0B | |
#MEMORY=`free --mega -h | awk '{ print "\t" $0 }'` | |
MEMORY=`free --mega -h | grep "Mem"` | |
MEMORY_TOTAL=`echo "$MEMORY" | awk '{ print $2 }'` | |
MEMORY_FREE=`echo "$MEMORY" | awk '{ print $4 }'` | |
MEMORY_OUTPUT=`printf "Total: %-5s Free: %-5s " $MEMORY_TOTAL $MEMORY_FREE` | |
# Filesystem Size Used Avail Use% Mounted on | |
# devtmpfs 3.7G 0 3.7G 0% /dev | |
# tmpfs 3.7G 0 3.7G 0% /dev/shm | |
# tmpfs 3.7G 33M 3.7G 1% /run | |
# tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup | |
# /dev/nvme0n1p2 16G 5.0G 12G 32% / | |
# /dev/nvme1n1 40G 1.7G 39G 5% /data | |
# tmpfs 757M 0 757M 0% /run/user/1000 | |
#DISK=`df -h | awk '{ print "\t" $0 }'` | |
DISK=`df -h` | |
DISK_ROOT_SIZE=`echo "$DISK" | grep "/dev/nvme0n1p2" | awk '{ print $2 }'` | |
DISK_ROOT_USED=`echo "$DISK" | grep "/dev/nvme0n1p2" | awk '{ print $3 }'` | |
DISK_ROOT_AVAIL=`echo "$DISK" | grep "/dev/nvme0n1p2" | awk '{ print $4 }'` | |
DISK_DATA_SIZE=`echo "$DISK" | grep "/dev/nvme1n1" | awk '{ print $2 }'` | |
DISK_DATA_USED=`echo "$DISK" | grep "/dev/nvme1n1" | awk '{ print $3 }'` | |
DISK_DATA_AVAIL=`echo "$DISK" | grep "/dev/nvme1n1" | awk '{ print $4 }'` | |
DISK_ROOT_OUTPUT=`printf "Size: %-5s Used: %-6s Avail: %-6s " $DISK_ROOT_SIZE $DISK_ROOT_USED $DISK_ROOT_AVAIL` | |
DISK_DATA_OUTPUT=`printf "Size: %-5s Used: %-6s Avail: %-6s " $DISK_DATA_SIZE $DISK_DATA_USED $DISK_DATA_AVAIL` | |
# ec2-user pts/0 2020-06-10 15:38 (172.30.0.160) | |
# WHO=`who` | |
echo " | |
┌──────────────────────────────────────────────────────────────────────────────────────────┐ | |
○ Server... $SERVER | |
○ Uptime... $UPTIME | |
○ Memory... $MEMORY_OUTPUT | |
○ Disk..... / $DISK_ROOT_OUTPUT | |
/data $DISK_DATA_OUTPUT | |
└──────────────────────────────────────────────────────────────────────────────────────────┘ | |
" | |
} | |
# Only display motd if tty | |
if [ "$PS1" ]; then | |
motd | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple quick login motd/stats
adjust the server-name, disk grep, etc for your system