From c7129b79537c3416a581f08460480b1dc284378c Mon Sep 17 00:00:00 2001 From: Gardouille Date: Tue, 8 Sep 2015 01:15:12 +0200 Subject: [PATCH] Add a new function to test network connection. Display "bonjour" function in zlogin only if a network connection is available --- zlogin | 7 +++++-- zshrc | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/zlogin b/zlogin index 4081122..876e24c 100644 --- a/zlogin +++ b/zlogin @@ -14,8 +14,11 @@ #echo "\n#### uptime ####" #uptime -# Affiche un dessin (cf fonction définie dans zshrc) -bonjour +# If a network connection is available (check function def in zshrc) +if ( is_network ); then + # Affiche un dessin (cf fonction définie dans zshrc) + bonjour +fi # Afficher la liste todo (paquet devtodo) printf '%b' "${MAGENTA}++++++++++++++++++++++ ${WHITEB}Liste de tâches${RESET} ${MAGENTA}:++++++++++++++++++++++${RESET}\n" diff --git a/zshrc b/zshrc index ae956a3..5c1a2e9 100644 --- a/zshrc +++ b/zshrc @@ -351,6 +351,19 @@ function ippriv() done } +# Test if a network connection is available +function is_network() +{ + for path_interface in $(find /sys/class/net/ ! -name lo -type l); + do + IS_UP=$(grep 1 ${path_interface}/carrier) + if [ ${IS_UP} ]; then + return 0 + fi + done + printf '%b' "${REDB}Not Online${RESET}\n" + return 1 +} #Renomme les fichiers en minuscule function lowercase()