[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Problem mit der Kombi cron und ifconfig



Hallo
ich habe ein Problem mit diesem Batch-Job:

    #!/bin/bash
    # WLAN-Verbindung vorhanden
    wlan_up=$(ifconfig wlan0 | grep -i -c 'inet Ad')
echo -e "$(date)\tifconfig: $wlan_up\twlan_up old: $(cat ${mydir}/wlan_up)\t\c" >>/root/pi_healtg.log
    if [ $wlan_up -eq 0 ]; then
       date +%s > ${mydir}/wlan_up
    else
       wlan_up=`expr $(date +%s) - $(cat ${mydir}/wlan_up)`
    fi

echo -e "Formel: expr $(date +%s) - $(cat ${mydir}/wlan_up) \t\c" >>/root/pi_healtg.log
    echo -e "wlan_up new: $wlan_up" >>/root/pi_healtg.log

Der Code wir periodisch alle 5 Minuten per cron.d aufgerufen:

    ###################################################
    # Alle 5 Minuten die wichtigsten Daten abfragen   #
    ###################################################
    */5 * * * *    root    /home/pi/pi_health

Das Ergebnis steht hier - die Einträge aus der 46 bzw. 47. Minuten erfolgten manuell als root:

Do 20. Nov 19:35:02 CET 2014 ifconfig: 0 wlan_up old: 1416508202 Formel: expr 1416508502 - 1416508502 wlan_up new: 0 Do 20. Nov 19:40:02 CET 2014 ifconfig: 0 wlan_up old: 1416508502 Formel: expr 1416508802 - 1416508802 wlan_up new: 0 Do 20. Nov 19:45:02 CET 2014 ifconfig: 0 wlan_up old: 1416508802 Formel: expr 1416509102 - 1416509102 wlan_up new: 0 Do 20. Nov 19:46:48 CET 2014 ifconfig: 1 wlan_up old: 1416509102 Formel: expr 1416509208 - 1416509102 wlan_up new: 106 Do 20. Nov 19:47:43 CET 2014 ifconfig: 1 wlan_up old: 1416509102 Formel: expr 1416509263 - 1416509102 wlan_up new: 161 Do 20. Nov 19:47:52 CET 2014 ifconfig: 1 wlan_up old: 1416509102 Formel: expr 1416509272 - 1416509102 wlan_up new: 170 Do 20. Nov 19:50:02 CET 2014 ifconfig: 0 wlan_up old: 1416509102 Formel: expr 1416509402 - 1416509402 wlan_up new: 0

Mich irritiert der unterschiedliche Wert für das Ergebnis von "ifconfig wlan0 | grep -i -c 'inet Ad'". Bei der Fehlersuche bin ich darauf gestoßen, dass beim Aufruf über cron ifconfig wlan0 leer ist.
Hat jemand eine Erklärung oder Lösung?

--
Gruß aus der Stadt der CeBIT
Jochen


Reply to: