Browse Source

updated motd example scripts

master
Mar Alegre 4 years ago
parent
commit
f8a02b0fe0
  1. 12
      docs/linux/motd/example/00-header
  2. 13
      docs/linux/motd/example/10-sysinfo
  3. 5
      docs/linux/motd/example/20-containers
  4. 4
      docs/linux/motd/example/40-zpool

12
docs/linux/motd/example/00-header

@ -1,11 +1,15 @@
#!/bin/bash
echo "Welcome to $(hostname)"
echo "Welcome to $(hostname -f)"
echo "$(date)"
echo "$(lsb_release -sd) $(uname -rm)"
upgrades=$(apt list -qq --upgradable 2> /dev/null | wc -l)
if [[ $upgrades == 0 ]]; then
printf "All packages are up to date.\n\n"
if [[ $upgrades -eq 0 ]]; then
echo "All packages are up to date."
elif [[ $upgrades -eq 1 ]]; then
echo "$upgrades package can be upgraded. Run 'apt list --upgradable' to see it."
elif [[ $upgrades -gt 1 ]]; then
echo "$upgrades packages can be upgraded. Run 'apt list --upgradable' to see them."
else
printf "$upgrades packages can be upgraded. Run 'apt list --upgradable' to see them.\n\n"
echo "Error getting list of upgradeable packages. Check your package system."
fi

13
docs/linux/motd/example/20-sysinfo → docs/linux/motd/example/10-sysinfo

@ -2,17 +2,12 @@
echo "System:"
echo " Uptime: $(uptime -p | cut -d' ' -f2-) (up since $(uptime -s))"
echo " Memory: $(free -h | grep Mem | perl -pe 's/Mem:\s+([\.\w]+)\s+([\.\w]+)\s+([\.\w]+).*/\1 total,
\2 used, \3 free/')"
echo " Swap: $(free -h | grep Swap | perl -pe 's/Swap:\s+([\.\w]+)\s+([\.\w]+)\s+([\.\w]+).*/\1 tota
l, \2 used, \3 free/')"
echo " Load Avg: $(cat /proc/loadavg | cut -d' ' -f1-3 | perl -pe 's/([\.\d]+) ([\.\d]+) ([\.\d]+)/\1 (a
vg 1 min), \2 (avg 5 min), \3 (avg 15 min)/')"
echo " Memory: $(free -h | grep Mem | perl -pe 's/Mem:\s+([\.\w]+)\s+([\.\w]+)\s+([\.\w]+).*/\1 total, \2 used, \3 free/')"
echo " Swap: $(free -h | grep Swap | perl -pe 's/Swap:\s+([\.\w]+)\s+([\.\w]+)\s+([\.\w]+).*/\1 total, \2 used, \3 free/')"
echo " Load: $(cat /proc/loadavg | cut -d' ' -f1-3 | perl -pe 's/([\.\d]+) ([\.\d]+) ([\.\d]+)/\1 (avg 1 min), \2 (avg 5 min), \3 (avg 15 min)/')"
users=$(w | tail -n +3 | cut -d' ' -f1 | sort | uniq -c | wc -l)
sessions=$(w | tail -n +3 | wc -l)
echo " Logins: $users users with $sessions sessions total"
ip=$(ip -4 addr show wan0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
name=$(host $ip | cut -d' ' -f5)
name=${name%?}
echo " WAN Addr: $ip (hostname $name)"
echo " WAN Addr: $ip"
echo ""

5
docs/linux/motd/example/20-containers

@ -0,0 +1,5 @@
#!/bin/bash
echo "Containers:"
podman ps -a --format=' NAMES\tIMAGE\tCREATED\tSTATUS\n {{.Names}}\t{{.Image}}\t{{.CreatedHuman}}\t{{.Status}}' | sed '3~2d'
echo ""

4
docs/linux/motd/example/40-zpool

@ -1,5 +1,5 @@
#!/bin/bash
echo "ZFS Pools:"
echo " $(zpool status -x)"
echo "ZFS Pool:"
zpool status | sed -E '/^\s*$/d' | sed -E 's/(.*)/ \1/'
echo ""

Loading…
Cancel
Save