Files
Server-scripts/utils/profile_motd2.sh
T
lucas 33473f3d5e chore(profile_motd): new profile motd script
reformat network print
reformat memory print
2026-11-04 11:29:20 +01:00

68 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
tab() {
if [ $# -lt 2 ]; then printf "\t"; fi
for ((i_tab=${#2};i_tab<$1;i_tab++)); do printf " "; done
}
if [ "$(/sbin/ip -br link | grep bond0)" != "" ];then
if1="bond0"
ip1="$(/sbin/ip -br link bond0 | grep -o "10\.0\.0\.103")"
if2="$(cat /proc/net/bonding/bond0 | grep 'Currently Active Slave:' | grep -o 'wlan0\|eth0')"
if [ "if2" == "" ]; then
printf "*******************************WTF? No bond IF2?*******************************\n"
fi
ip2="$(ip addr show $if2 | grep -o '10\.0\.0\.27\|10\.0\.0\.103')"
printf "%s:\t%s\t" "$if1" "$ip1"
else
ifx=( $(ip -br link | cut -f1 -d' ' | grep -v lo) )
for i in ${!ifx[@]}; do
ipx[$i]="$(ip addr show ${ifx[$i]} | grep -m1 -o -P '(?<=inet ).*(?=/24 brd)')"
if [ "${ipx[$i]}" == "" ]; then
ipx[$i]="----------"
fi
done
printf "%s:\t%s\t" "${ifx[0]}" "${ipx[0]}"
fi
ip="$(wget -T 5 -qO- ifconfig.co)"
location="$(wget -T 5 -qO- ifconfig.co/country)"
city=$(wget -T 5 -qO- ifconfig.co/city)
if [ "${ip}" == "" ]; then
ip="IP empty"
elif [ "${location}" == "" ]; then
location="No LOC"
elif [ "${city}" == "" ]; then
city="No City"
fi
printf "\tUser: $(whoami)"; tab 14 "$(whoami)"; printf "$ip"; tab 17 "$ip"; printf "$location\n"
if [ "$HOSTNAME" == "quiethost" ]; then
for ((i=1; i<${#ifx[@]}; i++)); do
printf "%s:\t%s" "${ifx[$i]}" "${ipx[$i]}"
if [ $i -eq 1 ]; then printf "\t\t\t\t\t\t${city}\n";
else printf "\n";
fi
done
fi
printf "\n"
SPACE_TAB=18
mem="$(free -h | awk 'NR==2 { printf "Total: %sB,\tUsed: %sB,\tFree: %sB",$2,$3,$7; }')"
printf "Memory:"; tab ${SPACE_TAB} "Memory:"; printf "$mem\n";
IFS=$'\n'; set -f
data_dev=($(df -h | grep "/dev/sd[a-f]" | sed 's/ \+/ /g' | cut -f1 -d' '))
unset IFS; set +f
osspace=""
for ((i=0;i<${#data_dev[@]};i++)); do
device="$(df -h "${data_dev[$i]}" | sed 's/ \+/ /g' | tail -1 | cut -f6 -d' ')"
if [ "$device" != "/" ]; then
device="/$(echo $device | rev | cut -f1 -d'/' |rev):"
else
device="/root:"
fi
if [[ "$(echo $device | grep "efi")" != "" ]] || [[ "$(echo $device | grep "win10")" != "" ]]; then continue; fi
osspace="$(df -h "${data_dev[$i]}" | awk 'NR==2 { printf "Total: %sB,\tUsed: %sB,\tFree: %sB\t%s used\n",$2,$3,$4,$5; }')"
printf "%s" "${device}"
tab ${SPACE_TAB} "${device}";
printf "%s\n" "$osspace"
done
tabs -8