This repository has been archived on 2025-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
debian_motd/20-network
2025-02-10 13:33:06 -03:00

29 lines
819 B
Bash

#!/bin/bash
interface=$(ip -o -4 route show to default | awk '{print $5}')
nic_in=$(grep $interface /proc/net/dev | awk '{print $2}')
nic_out=$(grep $interface /proc/net/dev | awk '{print $10}')
function human_readable {
VALUE=$1
if ! [[ "$VALUE" =~ ^[0-9]+$ ]]; then
echo "0B"
return
fi
BIGGIFIERS=( B Kb Mb Gb )
CURRENT_BIGGIFIER=0
while [ $VALUE -gt 10000 ] ;do
VALUE=$(($VALUE/1000))
CURRENT_BIGGIFIER=$((CURRENT_BIGGIFIER+1))
done
echo "$VALUE${BIGGIFIERS[$CURRENT_BIGGIFIER]}"
}
system_ip=$(hostname -I)
echo
echo "Network information:"
printf "System IP:\t%s\n" $system_ip
printf "Traffic in:\t%s\tTraffic out:\t%s\n" `human_readable $nic_in` `human_readable $nic_out`
echo