Created
January 20, 2017 00:12
-
-
Save Adadov/65f8713612ac581ae2ef0a6fe80e99ff to your computer and use it in GitHub Desktop.
Mon MOTD dynamique
This file contains hidden or 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 | |
function getIP() { | |
IFACE=$1 | |
IFCFG=$(/sbin/ifconfig ${IFACE} 2>&1 | /bin/grep "inet " ) | |
if [ $? -eq 0 ]; then | |
IP=$(echo ${IFCFG} | sed -r -e 's#\s*inet ([^ ]*).*#\1#;s/addr://') | |
else | |
IP="Not connected" | |
fi | |
echo ${IP} | |
} | |
function prtSysInfos { | |
TITLE="Systeme" | |
printf -v sep1 %${KEYSIZE}s | |
printf -v sep2 %$((${LARGEUR}-${#sep1}-${#TITLE}-4))s | |
printf "${Violet}${sep1// /+}: ${Blanc}${TITLE}${Violet} :${sep2// /+}\n" | |
i=0 | |
while [ $i -lt ${NBLINE} ]; do | |
i=$(($i+1)) | |
eval "KEY=\${L${i}K}" | |
eval "VAL=\${L${i}V}" | |
printf "${Violet}+ ${Blanc}%-$((${#sep1}-3))s${Violet}= ${Vert}%-$((${MAX}+2))s${Violet}+\n" "${KEY}" "${VAL}" | |
done | |
} | |
function prtLocIF { | |
local IFNAME=$1 | |
local IP=$(getIP ${IFNAME}) | |
printf "${Violet}+ ${Blanc}%-$((${#sep1}-3))s${Violet}= ${Vert}%-$((${MAX}+2))s${Violet}+\n" "IPv4 LAN" "${IFNAME} - ${IP}" | |
} | |
function prtPubIF { | |
# Detection de l'IP publique si elle n'est pas dans la configuration | |
if [ -z $PUBIP ]; then | |
PUBIP=$(wget -q -4 -O - http://icanhazip.com/ | tail) | |
fi | |
printf "${Violet}+ ${Blanc}%-$((${#sep1}-3))s${Violet}= ${Vert}%-$((${MAX}+2))s${Violet}+\n" "IPv4 Pub" "${PUBIP}" | |
} | |
function prtNetInfos { | |
TITLE="Reseau" | |
printf -v sep1 %${KEYSIZE}s | |
printf -v sep2 %$((${LARGEUR}-${#sep1}-${#TITLE}-4))s | |
echo -e "${Violet}${sep1// /+}: ${Blanc}${TITLE}${Violet} :${sep2// /+}" | |
if [ $SHOWPUB -eq 1 ]; then | |
prtPubIF | |
fi | |
for IF in ${MYIFS[@]}; do prtLocIF ${IF}; done | |
} | |
function prtEnd { | |
printf -v line %${LARGEUR}s | |
echo -e "${Violet}${line// /+}${NC}" | |
} | |
# Colors | |
NC="\033[0;0m" | |
Vert="\033[0;32m" | |
Violet="\033[0;35m" | |
Blanc="\033[0;37m" | |
BVert="\033[1;32m" | |
source /etc/hostConf | |
source /etc/os-release | |
: ${MYIFS:="eth0 wlan0"} | |
: ${SHOWPUB:=1} | |
: ${NBLINE:=3} | |
: ${KEYSIZE:=12} | |
MEMSIZEk=`cat /proc/meminfo | grep MemTotal | awk {'print $2'}` | |
MEMSIZE="$((${MEMSIZEk}/1024)) MB" | |
L1K="Systeme" | |
L1V="$(hostname) / ${PRETTY_NAME}" | |
L2K="Fonction" | |
L2V="$(uptime | sed -r 's/.*up\s+([^,]*), .*/\1/')" | |
L3K="Memoire" | |
L3V="${MEMSIZE}" | |
: ${MAX:=${#L1V}} | |
LARGEUR=$((${#L1V}+5+${KEYSIZE})) | |
prtSysInfos | |
prtNetInfos | |
prtEnd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment