DooM a écrit 12 commentaires

  • [^] # Re: MAJ SCRIPT

    Posté par  . En réponse au message Le plus petit. Évalué à 1.

    wow !

    C'est sûr que le script est beaucoup plus organisé et compact comme ça :)

    Maintenant il ne me reste plus qu'à le comprendre !!! Mais merci je vais plancher là-dessus ;)

  • # MAJ SCRIPT

    Posté par  . En réponse au message Le plus petit. Évalué à 0.

    Bonsoir !

    Mise à jour du script !!!!

    MAJ 28 AOÛT :

    • Détecte les échecs de connexion, et essaie sur le prochain serveur le moins chargé
    • En cas d'essai infructueux sur tous les serveurs, arrête et propose de vérifier les paramètres de connexion

    Encore merci pour votre aide !!! :D

    #!/bin/bash
    # FREEDOM-IP AUTO CONNECT SCRIPT
    
    ETH_DEV="eth0"
    WLN_DEV="wlan0"
    
    
    # ANALYSE INTERFACE RÉSEAU ACTIVE
    echo
    echo ----- ANALYSE INTERFACE RÉSEAU
    NET_STAT=$(nmcli con status | egrep "${ETH_DEV}|${WLN_DEV}")
    echo
    echo $NET_STAT est la connexion active
    
    
    # VÉRIFICATION D'ÉTABLISSEMENT COMPLET DE LA CONNECTIVITÉ INTERNET
    echo
    echo ----- VÉRIFICATION INTERNET...
    CURRENT_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
    PING=$(ping -c 3 vpn2.freedom-ip.com | grep % | cut -d ' ' -f4)
    echo
    echo Adresse IP actuelle: $CURRENT_IP
    echo
    echo $PING sur 3 paquets reçus depuis vpn2.freedom-ip.com
    if [ -z $PING ]; then
        echo
        echo Pas de connexion Internet fonctionnelle        
        notify-send 'Freedom-IP:' 'Pas de connexion Internet fonctionnelle' -i dialog-error
        exit
    fi
    
    # OCCUPATION DES SERVEURS
    echo
    echo ----- OCCUPATION DES SERVEURS
    wget --no-check-certificate -O /tmp/fip_occupation https://freedom-ip.com/statistiques.php
    SERV_LOAD=$(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2)
    echo
    echo $SERV_LOAD
    
    SERV_MIN_LOAD=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -rn | tail -n1) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    echo
    echo $SERV_MIN_LOAD est le moins occupé, sélection pour connexion
    notify-send "Occupation des serveurs" "$SERV_MIN_LOAD est le moins occupé, sélection pour connexion"
    
    SERV_MIN_LOAD_2=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -rn | tail -n2) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    
    SERV_MIN_LOAD_3=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -rn | tail -n3) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    
    SERV_MIN_LOAD_4=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -rn | tail -n4) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    
    SERV_MIN_LOAD_5=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -rn | tail -n5) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    
    SERV_MIN_LOAD_6=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -rn | tail -n6) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    
    SERV_MIN_LOAD_7=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -rn | tail -n7) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    
    SERV_MIN_LOAD_8=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -rn | tail -n8) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    
    
    # VÉRIFICATION D'UNE CONNEXION AU VPN DÉJÀ EXISTANTE
    echo
    echo ----- VERIFICATION
    VPN_STAT=$(nmcli con status | grep freedomip | cut -d\  -f 1)
    if [ -z "${VPN_STAT}" ]; then
    echo
    echo Pas de connexion VPN active
    notify-send 'Freedom-IP:' "Établissement de la connexion sécurisée..." -i dialog-warning ; else
    echo
    echo Déjà connecté à $VPN_STAT - Redémarrage avec $SERV_MIN_LOAD
    notify-send "Déjà connecté à $VPN_STAT" "Redémarrage avec $SERV_MIN_LOAD" -i dialog-warning
    echo
    echo ----- DÉCONNEXION DE $VPN_STAT
    nmcli con down id "${VPN_STAT}"
    echo
    echo OK
    echo
    echo ----- RECONNEXION À $SERV_MIN_LOAD'_freedomip'
    echo
    RCON=$(nmcli con up id $SERV_MIN_LOAD'_freedomip' | grep "Connexion activée")
    echo $RCON
        if [ "$RCON" = "Connexion activée" ]; then
        NEW_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
        echo
        echo Nouvelle IP: $NEW_IP
        sleep 3
        notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD" -i dialog-information ; else
        echo
        echo Impossible de se connecter à $SERV_MIN_LOAD   
        notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD, essai avec $SERV_MIN_LOAD_2" -i dialog-error
            if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
            CON_2=$(nmcli con up id $SERV_MIN_LOAD_2'_freedomip' | grep "Connexion activée")
            echo $CON_2
            sleep 3
            notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_2" -i dialog-information; else
            echo Impossible de se connecter à $SERV_MIN_LOAD_2 
            notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_2, essai avec $SERV_MIN_LOAD_3" -i dialog-error
                if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                CON_2=$(nmcli con up id $SERV_MIN_LOAD_3'_freedomip' | grep "Connexion activée")
                echo $CON_3
                sleep 3
                notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_3" -i dialog-information; else
                echo Impossible de se connecter à $SERV_MIN_LOAD_2 
                notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_3, essai avec $SERV_MIN_LOAD_4" -i dialog-error
                    if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                    CON_4=$(nmcli con up id $SERV_MIN_LOAD_4'_freedomip' | grep "Connexion activée")
                    echo $CON_4
                    sleep 3
                    notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_4" -i dialog-information; else
                    echo Impossible de se connecter à $SERV_MIN_LOAD_4 
                    notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_4, essai avec $SERV_MIN_LOAD_5" -i dialog-error
                        if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                        CON_5=$(nmcli con up id $SERV_MIN_LOAD_5'_freedomip' | grep "Connexion activée")
                        echo $CON_5
                        sleep 3
                        notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_5" -i dialog-information; else
                        echo Impossible de se connecter à $SERV_MIN_LOAD_5 
                        notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_5, essai avec $SERV_MIN_LOAD_6" -i dialog-error
                            if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                            CON_6=$(nmcli con up id $SERV_MIN_LOAD_6'_freedomip' | grep "Connexion activée")
                            echo $CON_6
                            sleep 3
                            notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_6" -i dialog-information; else
                            echo Impossible de se connecter à $SERV_MIN_LOAD_6 
                            notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_6, essai avec $SERV_MIN_LOAD_7" -i dialog-error
                                if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                                CON_7=$(nmcli con up id $SERV_MIN_LOAD_7'_freedomip' | grep "Connexion activée")
                                echo $CON_7
                                sleep 3
                                notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_7" -i dialog-information; else 
                                echo Impossible de se connecter à $SERV_MIN_LOAD_7 
                                notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_7, essai avec $SERV_MIN_LOAD_8" -i dialog-error
                                    if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                                    CON_8=$(nmcli con up id $SERV_MIN_LOAD_8'_freedomip' | grep "Connexion activée")
                                    echo $CON_8
                                    sleep 3
                                    notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_8" -i dialog-information; else 
                                    echo Impossible de se connecter à $SERV_MIN_LOAD_8 
                                    notify-send 'Freedom-IP:' "Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !" -i dialog-error
                                    fi
                                fi
                            fi
                        fi
                    fi
                fi
            fi
        fi
    echo
    echo ----- FIN DE SCRIPT
    exit
    fi
    
    
    # CONNECTION AU VPN SI INTERNET CONNECTÉ
    if [ $PING -eq 3 ]; then
        echo
        echo ----- CONNEXION À $SERV_MIN_LOAD
        echo
        if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
        CON=$(nmcli con up id $SERV_MIN_LOAD'_freedomip' | grep "Connexion activée")
        echo $CON
        fi
    fi
        if [ "$CON" = "Connexion activée" ]; then
        NEW_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
        echo
        echo Nouvelle IP: $NEW_IP
        sleep 3
        notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD" -i dialog-information ; else
        echo
        echo Impossible de se connecter à $SERV_MIN_LOAD   
        notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD, essai avec $SERV_MIN_LOAD_2" -i dialog-error   
            if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
            CON_2=$(nmcli con up id $SERV_MIN_LOAD_2'_freedomip' | grep "Connexion activée")
            echo $CON_2
            sleep 3
            notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_2" -i dialog-information; else
            echo Impossible de se connecter à $SERV_MIN_LOAD_2 
            notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_2, essai avec $SERV_MIN_LOAD_3" -i dialog-error
                if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                CON_2=$(nmcli con up id $SERV_MIN_LOAD_3'_freedomip' | grep "Connexion activée")
                echo $CON_3
                sleep 3
                notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_3" -i dialog-information; else
                echo Impossible de se connecter à $SERV_MIN_LOAD_2 
                notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_3, essai avec $SERV_MIN_LOAD_4" -i dialog-error
                    if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                    CON_4=$(nmcli con up id $SERV_MIN_LOAD_4'_freedomip' | grep "Connexion activée")
                    echo $CON_4
                    sleep 3
                    notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_4" -i dialog-information; else
                    echo Impossible de se connecter à $SERV_MIN_LOAD_4 
                    notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_4, essai avec $SERV_MIN_LOAD_5" -i dialog-error
                        if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                        CON_5=$(nmcli con up id $SERV_MIN_LOAD_5'_freedomip' | grep "Connexion activée")
                        echo $CON_5
                        sleep 3
                        notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_5" -i dialog-information; else
                        echo Impossible de se connecter à $SERV_MIN_LOAD_5 
                        notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_5, essai avec $SERV_MIN_LOAD_6" -i dialog-error
                            if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                            CON_6=$(nmcli con up id $SERV_MIN_LOAD_6'_freedomip' | grep "Connexion activée")
                            echo $CON_6
                            sleep 3
                            notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_6" -i dialog-information; else
                            echo Impossible de se connecter à $SERV_MIN_LOAD_6 
                            notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_6, essai avec $SERV_MIN_LOAD_7" -i dialog-error
                                if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                                CON_7=$(nmcli con up id $SERV_MIN_LOAD_7'_freedomip' | grep "Connexion activée")
                                echo $CON_7
                                sleep 3
                                notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_7" -i dialog-information; else 
                                echo Impossible de se connecter à $SERV_MIN_LOAD_7 
                                notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD_7, essai avec $SERV_MIN_LOAD_8" -i dialog-error
                                    if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
                                    CON_8=$(nmcli con up id $SERV_MIN_LOAD_8'_freedomip' | grep "Connexion activée")
                                    echo $CON_8
                                    sleep 3
                                    notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD_8" -i dialog-information; else 
                                    echo Impossible de se connecter à $SERV_MIN_LOAD_8 
                                    notify-send 'Freedom-IP:' "Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !" -i dialog-error
                                    fi
                                fi
                            fi
                        fi
                    fi
                fi
            fi
        fi
    
    echo
    echo ----- FIN DE SCRIPT
    exit
    
    
  • [^] # Re: SCRIPT COMPLET

    Posté par  . En réponse au message Le plus petit. Évalué à 0.

    LoL oui je suis aussi toujours à la recherche de la "perfection".

    Mais je commence seulement à tâter du bash script, et là ça me rajoute des lignes. Alors que je cherche au contraire à y voir plus clair en en mettant le moins possible.

    Mais merci quand même, ça peut toujours servir !

  • [^] # Re: SCRIPT COMPLET

    Posté par  . En réponse au message Le plus petit. Évalué à 1.

    Ok je comprends :)

    Du coup j'ai modifié comme ceci pour conserver un retour terminal "propre" :

    echo ----- VÉRIFICATION INTERNET...
    PING=$(ping -c 3 vpn2.freedom-ip.com | grep % | cut -d ' ' -f4)
    echo
    echo $PING sur 3 paquets reçus depuis vpn2.freedom-ip.com
    if [ -z $PING ]; then
        echo
        echo Pas de connexion Internet fonctionnelle        
        notify-send 'Freedom-IP:' 'Pas de connexion Internet fonctionnelle' -i dialog-error
        exit
    fi
    
    
  • # SCRIPT COMPLET

    Posté par  . En réponse au message Le plus petit. Évalué à 1.

    Pour ceux que ça intéresserait, voici le script complet.

    Je sais qu'il pourrait être nettoyé, optimisé et qu'on pourrait même y ajouter certaines fonctions. Mais pour l'instant c'est le mieux que je puisse faire !

    Le script à pour but de connecter automatiquement un serveur OpenVPN au démarrage d'une session Linux à condition de de l'avoir ajouté à gnome-session-properties, ou d'avoir créé un lanceur .desktop dans /etc/xdg/autostart/, ou encore de l'avoir placé dans /etc/NetworkManager/Dispatcher.d/ (dans ce dernier cas aucune déconnexion sera possible, et les notifications ne s'afficheront pas).

    Voici le code, originalement créé pour la communauté Freedom-Ip qui offre un service OpenVPN gratuit.

    Mais attention ! Ce script cherche les valeurs freedomip retournées par le NerworkManager d'Ubuntu, pensez à le modifier en conséquence ;)

    Fonctions du script:

    • Cherche l'interface réseau active (limité à wlan0 & eth0)
    • Vérifie que la connexion internet soit bien opérationnelle via ping, sinon stop l'opération
    • Récupère l'occupation des serveurs et détermine le moins occupé via wget / http (à adapter en fonction de votre fournisseur!)
    • Vérifie qu'aucune connexion VPN (ici à Freedom-IP) ne soit active. Si c'est le cas, déconnecte puis reconnecte au serveur le moins occupé
    • Sinon connecte tout simplement le serveur le moins occupé, à condition qu'une interface réseau (wlan0 ou eth0) et qu'aucun VPN Freedom-IP ne soient actifs
    • Retours terminal étape par étape
    • Retours de notifications graphiques via libnotify : Pas d'internet, VPN déjà connecté, Serveur le moins occupé, Reconnexion, Connexion, Erreur de connexion

    Script:

    #!/bin/bash
    #
    # FREEDOM-IP AUTO CONNECT SCRIPT
    #
    # DÉPENDANCES: nmcli ping wget openvpn network-manager-openvpn network-manager-openvpn-gnome openssl libnotify
    
    
    ETH_DEV="eth0"
    WLN_DEV="wlan0"
    
    
    # ANALYSE INTERFACE RÉSEAU ACTIVE
    echo
    echo ----- ANALYSE INTERFACE RÉSEAU
    NET_STAT=$(nmcli con status | egrep "${ETH_DEV}|${WLN_DEV}")
    echo
    echo $NET_STAT est la connexion active
    
    
    # VÉRIFICATION D'ÉTABLISSEMENT COMPLET DE LA CONNECTIVITÉ INTERNET
    echo
    echo ----- VÉRIFICATION INTERNET...
    PING=$(ping -c 3 vpn2.freedom-ip.com | grep received | cut -d ',' -f2 | cut -d ' ' -f2)
    echo
    echo $PING sur 3 paquets reçus depuis vpn2.freedom-ip.com
    if [ -z $PING ]; then
        echo
        echo Pas de connexion Internet fonctionnelle        
        notify-send 'Freedom-IP:' 'Pas de connexion Internet fonctionnelle' -i dialog-error
        exit
    fi
    
    # OCCUPATION DES SERVEURS
    echo
    echo ----- OCCUPATION DES SERVEURS
    wget --no-check-certificate -O /tmp/fip_occupation https://freedom-ip.com/statistiques.php
    SERV_LOAD=$(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2)
    echo
    echo $SERV_LOAD
    
    SERV_MIN_LOAD=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    echo
    echo $SERV_MIN_LOAD est le moins occupé, sélection pour connexion
    notify-send "Occupation des serveurs" "$SERV_MIN_LOAD est le moins occupé, sélection pour connexion"
    
    
    # VÉRIFICATION D'UNE CONNEXION AU VPN DÉJÀ EXISTANTE
    echo
    echo ----- VERIFICATION
    VPN_STAT=$(nmcli con status | grep freedomip | cut -d\  -f 1)
    if [ -z "${VPN_STAT}" ]; then
    echo
    echo Pas de connexion VPN active
    notify-send 'Freedom-IP:' 'Établissement de la connexion sécurisée...' -i dialog-warning ; else
    echo
    echo Déjà connecté à $VPN_STAT - Redémarrage avec $SERV_MIN_LOAD
    notify-send "Déjà connecté à $VPN_STAT" "Redémarrage avec $SERV_MIN_LOAD" -i dialog-warning
    echo
    echo ----- DÉCONNEXION DE $VPN_STAT
    nmcli con down id "${VPN_STAT}"
    echo
    echo ----- RECONNEXION À $SERV_MIN_LOAD
    echo
    RCON=$(nmcli con up id $SERV_MIN_LOAD'_freedomip' | grep "Connexion activée")
    echo $RCON
        if [ "$RCON" = "Connexion activée" ]; then
        sleep 3
        notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD, surfez tranquile :-)" -i dialog-information ; else
        echo
        echo Impossible de se connecter à $SERV_MIN_LOAD   
        notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD" -i dialog-error
        fi
    echo
    echo ----- FIN DE SCRIPT
    exit
    fi
    
    
    # CONNECTION AU VPN SI INTERNET CONNECTÉ
    if [ $PING -eq 3 ]; then
        echo
        echo ----- CONNEXION À $SERV_MIN_LOAD
        echo
        if [ ! -z "${NET_STAT}" -a -z "${VPN_STAT}" ]; then
        CON=$(nmcli con up id $SERV_MIN_LOAD'_freedomip' | grep "Connexion activée")
        echo $CON
        fi
    fi
        if [ "$CON" = "Connexion activée" ]; then
        sleep 3
        notify-send "Connexion sécurisée établie au server $SERV_MIN_LOAD, surfez tranquile :-)" -i dialog-information ; else
        echo
        echo Impossible de se connecter à $SERV_MIN_LOAD   
        notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MIN_LOAD" -i dialog-error
        fi
    
    echo
    echo ----- FIN DE SCRIPT
    exit
    
    

    Encore un grand merci à vous tous pour votre aide précieuse ;)

  • [^] # Re: Parfait !

    Posté par  . En réponse au message Le plus petit. Évalué à 0.

    wow !

    Cela me dépasse complètement !!!

    Mais qui sait, vu que je le retrouve de plus en plus souvent confronté à la nécessité du bash script, ça pourrait bien m'être utile un jour :))

    Merci :))

  • [^] # Re: en shell

    Posté par  . En réponse au message Le plus petit. Évalué à 0. Dernière modification le 24 août 2012 à 14:35.

    Oui c'est curieux, je pense que ça doit venir du fait que j'intègre la commande dans la variable SERV_MIN_LOAD=$( )

    Mais grâce à vous tous, le script fonctionne enfin !! Merci !! Voir dernier commentaire :)

  • # Parfait !

    Posté par  . En réponse au message Le plus petit. Évalué à 1. Dernière modification le 24 août 2012 à 13:31.

    Parfait !!!

    Voici la ligne de script :

    SERV_MIN_LOAD=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n) | cut -d ' ' -f2 | cut -d '
    ' -f1)
    echo $SERV_MIN_LOAD est le moins occupé
    
    

    qui me retourne :

    IE3 est le moins occupé
    
    

    De fait, le serveur le moins occupé est définit dans $SERV_MIN_LOAD , ce qui me permet de la réutiliser pour la connexion :D

    Un grand merci à tous !!!

  • [^] # Re: Solution quick & dirty Bash

    Posté par  . En réponse au message Le plus petit. Évalué à 0. Dernière modification le 24 août 2012 à 12:07.

    avec

    awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i  } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2) | sort -n
    
    

    j'ai les résultats dans l'ordre ! :)

  • [^] # Re: Solution quick & dirty Bash

    Posté par  . En réponse au message Le plus petit. Évalué à 0.

    Me donne le même résultat mais efface "personnes connectées à"

  • [^] # Re: en shell

    Posté par  . En réponse au message Le plus petit. Évalué à 1. Dernière modification le 24 août 2012 à 11:56.

    Bonjour !

    En effet, quand je lance la commande seule dans un terminal les résultats sont bien affichés avec des retours de ligne.
    Par contre dans le script tout s'affiche à la suite… :(

    PS: fip_occupation n'est pas un script mais la page .php qui affiche l'occupation des serveurs et que je récupère directement avec wget.

    J'ai édité le post original pour l'exemple :)

  • [^] # Re: question

    Posté par  . En réponse au message Le plus petit. Évalué à 0.

    Bonjour !

    Je ne comprends pas pourquoi, je lance ma commande seule dans un terminal le résultat est affiché avec des retours de ligne (1 serveur par ligne) mais ce n'est pas le cas en exécutant le script