Oscam Cardserver überwachen (Rapberry): Unterschied zwischen den Versionen

Aus Tutorials
Zur Navigation springen Zur Suche springen
 
(20 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 2: Zeile 2:




=== PID ermitteln ===
== Datei erstellen ==
 
<pre>
<pre>
pidof /usr/local/bin/oscam
sudo touch /usr/local/bin/check_oscam.sh
sudo chmod a+x /usr/local/bin/check_oscam.sh
</pre>
</pre>
=== Script ===


<pre>
<pre>
sudo vi /usr/local/bin/oscam_watchdog.sh
sudo vi /usr/local/bin/check_oscam.sh
</pre>
</pre>


<pre>
#!/bin/bash


PIDFILE=/var/run/oscam.pid
[[Medium:Check oscam.zip]]
if (kill -0 `cat $PIDFILE`)
then
echo "it's alive!" > /dev/null
else
rm $PIDFILE
/usr/local/bin/oscam start > /dev/null
echo "OSCAM restarted at `date`" >> /var/log/oscam-crash.log
fi
</pre>
 
<pre>
sudo chmod +x /usr/local/bin/oscam_watchdog.sh
</pre>


== Implementierung ==


[[Medium:Check oscam.zip]]
=== Header ===


<pre>
<pre>
Zeile 99: Zeile 83:
'
'
if [ "$#" -lt "6" ]; then
if [ "$#" -lt "6" ]; then
        echo -e "$howto" && exit "3"
  echo -e "$howto" && exit "3"
fi
fi


Zeile 126: Zeile 110:


if [ "$strpart" == "entitlement" ] && [ "$strEnt0" == "" ]; then
if [ "$strpart" == "entitlement" ] && [ "$strEnt0" == "" ]; then
        echo -e "$howto" && exit "3"
  echo -e "$howto" && exit "3"
fi
fi


Zeile 135: Zeile 119:
# Remove old File
# Remove old File
rm -f ""$temp"/status.html"
rm -f ""$temp"/status.html"
</pre>


=== Function statuscheck() ===


<pre>
statuscheck() {
statuscheck() {
    #echo "$strHostname:$strPort"
  #echo "$strHostname:$strPort"
    rm -f "$temp"/status.html
  rm -f "$temp"/status.html
    # File Download
  # File Download
    a=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/status.html" "http://$strHostname:$strPort/status.html"  >/dev/null 2>/dev/null)
  a=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/status.html" "http://$strHostname:$strPort/status.html"  >/dev/null 2>/dev/null)
    if [ $? -eq 0 ]
  if [ $? -eq 0 ]
    then
  then
    {        lines=$(wc -l ""$temp"/status.html" | awk '{print $1}')
  {         
    lines=$(wc -l ""$temp"/status.html" | awk '{print $1}')


            if [ $lines -lt 2 ] ; then
    if [ $lines -lt 2 ]; then
                t=$(tail -n 1 ""$temp"/status.html")
      t=$(tail -n 1 ""$temp"/status.html")
                echo "CRITICAL: " $t
      echo "CRITICAL: " $t
                    # Logging
      # Logging
                        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $t"; fi
      if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $t"; fi
                        if [ $debug -eq 1 ] ;then echo -e "Fehler - Status.html hat <2 Zeilen und sieht somit nicht korrekt aus." ; fi
      if [ $debug -eq 1 ] ;then echo -e "Fehler - Status.html hat <2 Zeilen und sieht somit nicht korrekt aus." ; fi


                exit 2;
      exit 2;
            else
    else
            {
    {
                # Datei hat mehr als 1 Zeile - also suche nach Karten
      # Datei hat mehr als 1 Zeile - also suche nach Karten
                    c=0
      c=0
                    z=0
      z=0
                    readerName="strReader"
      readerName="strReader"
                    if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife  um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName" ; fi
      if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife  um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName" ; fi
                    while [ $z == 0 ]
      while [ $z == 0 ]
                    do
      do
                        {
      {
                            # Zähle ReaderNamen hoch
        # Zähle ReaderNamen hoch
                            readerNameComp="$readerName$c"
        readerNameComp="$readerName$c"
                            if [ $debug -eq 1 ] ;then echo -e  "Readername = readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}" ; fi
        if [ $debug -eq 1 ] ;then echo -e  "Readername = readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}" ; fi


                            # Suche nach Karte
        # Suche nach Karte
                            b=$(grep '<TD CLASS="statuscol16">CARDOK<BR><A HREF="entitlements.html?label='${!readerNameComp}'&amp;hideexpired=1"' "$temp"/status.html)
        b=$(grep '<TD CLASS="statuscol16">CARDOK<BR><A HREF="entitlements.html?label='${!readerNameComp}'&amp;hideexpired=1"' "$temp"/status.html)
                            if [ $debug -eq 1 ] ;then echo -e "Suchstring="$b"" ; fi
        if [ $debug -eq 1 ] ;then echo -e "Suchstring="$b"" ; fi
                            if [ $? -eq 0 ]
        if [ $? -eq 0 ]; then
                                then
          #Grep erfolgreich - aber noch nicht klar ob string gefunden
                                        #Grep erfolgreich - aber noch nicht klar ob string gefunden
          if [ ! "$b" == "" ]; then
                                        if [ ! "$b" == "" ]
            #echo "Karte - OK"
                                        then
            if [ ! "$y" == "NOK" ] ; then  y="OK" ; fi
                                            #echo "Karte - OK"
            e=""$e"OK: ${!readerNameComp} - "
                                            if [ ! "$y" == "NOK" ] ; then  y="OK" ; fi
            if [ $debug -eq 1 ] ;then  echo -e "Sieht gut aus - String wurde gefunden. y=$y\ne=$e" ; fi
                                            e=""$e"OK: ${!readerNameComp} - "
            # pattern found
                                            if [ $debug -eq 1 ] ;then  echo -e "Sieht gut aus - String wurde gefunden. y=$y\ne=$e" ; fi
            # Alles gut - lösche falls vorhanden die Antiloop Datei
                                            # pattern found
            rm -f ""$temp"/${!readerNameComp}"
                                            # Alles gut - lösche falls vorhanden die Antiloop Datei
          else
                                            rm -f ""$temp"/${!readerNameComp}"
            # String nicht gefunden, also Karte nicht OK
                                        else
            #echo "Karte - Not OK"
                                            # String nicht gefunden, also Karte nicht OK
            y=("NOK")
                                            #echo "Karte - Not OK"
            e=""$e"CRITICAL: ${!readerNameComp} - "
                                            y=("NOK")
            if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
                                            e=""$e"CRITICAL: ${!readerNameComp} - "
            if [ $debug -eq 1 ] ;then  echo -e "Sieht schlecht aus - String nicht gefunden. (1.  Abfrage)\ny=$y\ne=$e" ; fi
                                            if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
          fi
                                            if [ $debug -eq 1 ] ;then  echo -e "Sieht schlecht aus - String nicht gefunden. (1.  Abfrage)\ny=$y\ne=$e" ; fi
        else
                                        fi
          #echo "Karte - Not OK"
                                else
          y=("NOK")
                                        #echo "Karte - Not OK"
          e=""$e"CRITICAL: ${!readerNameComp} - "
                                        y=("NOK")
          if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
                                        e=""$e"CRITICAL: ${!readerNameComp} - "
          if [ $debug -eq 1 ] ;then echo  -e "Sieht schlecht aus - String nicht gefunden.(2. Abfrage)\ny=$y\ne=$e"  ; fi
                                        if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
        fi # Ende If
                                        if [ $debug -eq 1 ] ;then echo  -e "Sieht schlecht aus - String nicht gefunden.(2. Abfrage)\ny=$y\ne=$e"  ; fi
                                fi


                            # Ende If
        tempCount=$[$c + 1]
        if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
        readerNameComp="$readerName$tempCount"
        if [ $debug -eq 1 ] ;then echo -e "Demnach  ist der nächste Reader: $readerNameComp\nDas sollte sein: ${!readerNameComp}" ; fi


                            tempCount=$[$c + 1]
        if [ "${!readerNameComp}" == "" ]; then
                            if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
          z=$[$z + 1]
                            readerNameComp="$readerName$tempCount"
          if [ $debug -eq 1 ] ;then echo -e "So  der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
                            if [ $debug -eq 1 ] ;then echo -e "Demnach  ist der nächste Reader: $readerNameComp\nDas sollte  sein:${!readerNameComp}" ; fi
        else
          # Zähle Reader hoch
          c=$[$c + 1]
          if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
          fi
        }
      done


                            if [ "${!readerNameComp}" == "" ] ; then
      if [ "$y" == 'OK' ]; then
                                z=$[$z + 1]
        echo "$e"
                                if [ $debug -eq 1 ] ;then echo -e "So  der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
        # Logging
                            else
        if [ "$logsyslog"  == "1" ] ; then   logger  "$filename $version - $e"; fi
                                # Zähle Reader hoch
        if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = OK - also Exit 0." ; fi
                                c=$[$c + 1]
        exit 0
                                if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
      fi
                            fi
                        }
                    done


                    if [ "$y"  == 'OK' ] ; then
      if [ "$y" == "NOK" ]; then
                        echo "$e"
        echo "$e"
                        # Logging
        # Logging
                                if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
                                if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = OK - also Exit 0." ; fi
        if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = NOK - also Exit 2." ; fi
                        exit 0
        exit 2
                    fi
      fi
 
                    if [ "$y" == "NOK" ] ; then
                        echo "$e"
                        # Logging
                                if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
                                if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = NOK - also Exit 2." ; fi
                        exit 2
                    fi
            }
            fi
     }
     }
    else
        {
        echo "CRITICAL: Could not download status.html (StatusCheck)"
        # Logging
            if [ "$logsyslog"  == "1" ] ; then    logger  "$filename  $version - CRITICAL: Could not download status.html (StatusCheck)"; fi
        exit 2;
        }
     fi
     fi
  }
  else
  {
    echo "CRITICAL: Could not download status.html (StatusCheck)"
    # Logging
    if [ "$logsyslog"  == "1" ] ; then    logger  "$filename  $version - CRITICAL: Could not download status.html (StatusCheck)"; fi
    exit 2;
  }
  fi
}
}
</pre>


=== Function readerRestart() ===


<pre>
readerRestart() {
readerRestart() {
        if [ $debug -eq 1 ] ;then echo -e "Beginne Restart Funktion - Übergabewert (Readername) ist: $1" ; fi
  if [ $debug -eq 1 ] ;then echo -e "Beginne Restart Funktion - Übergabewert (Readername) ist: $1" ; fi
#       echo "$strHostname:$strPort"
 
        rm -f ""$temp"/readers.html"
  # echo "$strHostname:$strPort"
        # Check das Loop nicht Größer X ist - damit die Reader nicht dauernd neu gestartet werden
  rm -f ""$temp"/readers.html"
        r=$(cat "$temp/$1" 2>/dev/null)
        if [ ""$r""  == "" ] ; then r=0 ;if [ $debug -eq 1 ] ;then echo  -e "Temp. Restartdatei existiert noch nicht. r=$r" ; fi;  fi
        if [ "$r"  -ge "$anticount" ]  ; then
                                echo "CRITICAL: Nach $r Versuchen kein Reader restart mehr."
                                    # Logging
                                        if [ "$logsyslog"  == "1" ] ;  then    logger  "$filename $version - CRITICAL: Nach $r Versuchen kein  Reader restart mehr."; fi
                                #        if [ $debug -eq 1 ] ;then echo  -e "$filename $version - CRITICAL: Nach $r Versuchen kein Reader restart  mehr." ; fi
                #    Deaktiviert, da sonst das Skript komplett beendet wird
                #              exit 2;
        else


            # File Download
  # Check das Loop nicht Größer X ist - damit die Reader nicht dauernd neu gestartet werden
            if [ $debug -eq 1 ] ;then echo -e "readers.html wird runtergeladen - bzw. befehl disable befehl ausgeführt" ; fi
  r=$(cat "$temp/$1" 2>/dev/null)
            g=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass""  --anyauth -o ""$temp"/readers.html"  "http://$strHostname:$strPort/readers.html?label=$1&action=disable" >/dev/null 2>/dev/null)
            if [ $? -eq 0 ]
            then
                    # Antiloop hochzählen
                    echo $[$r+1] > "$temp/$1"


                    # Zähle Zeilen um Fehler fest zu stellen ( Datei muss <1 Zeile sein )
  if [ ""$r""  == "" ]; then
                    lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
    r=0;
    if [ $debug -eq 1 ]; then
      echo -e "Temp. Restartdatei existiert noch nicht. r=$r";
    fi;
  fi


                    if [ $lines -lt 2 ] ; then
  if [ "$r" -ge "$anticount" ]; then
                    s=$(tail -n 1 ""$temp"/readers.html")
    echo "CRITICAL: Nach $r Versuchen kein Reader restart mehr."
                    echo "CRITICAL: " $s
    # Logging
                        # Logging
    if [ "$logsyslog"  == "1" ]; then
                            if [ "$logsyslog"  == "1" ] ; then   logger  "$filename $version - CRITICAL: $s"; fi
      logger  "$filename $version - CRITICAL: Nach $r Versuchen kein  Reader restart mehr.";  
        #    Deaktiviert, da sonst das Skript komplett beendet wird
    fi
        #                    exit 2;


                    else
    # if [ $debug -eq 1 ] ;then echo  -e "$filename $version - CRITICAL: Nach $r Versuchen kein Reader restart  mehr." ; fi
                            # Datei hat mehr als 1 Zeile - also suche nach Karten
    # Deaktiviert, da sonst das Skript komplett beendet wird
                            echo "WARNING: Reader $1 disabled"
    # exit 2;
                            # Aufräumen vor dem aktivieren
  else
                            rm -f ""$temp"/readers.html"
    # File Download
                            lines=""
    if [ $debug -eq 1 ] ;then echo -e "readers.html wird runtergeladen - bzw. befehl disable befehl ausgeführt" ; fi
                            s=""
    g=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth -o ""$temp"/readers.html" "http://$strHostname:$strPort/readers.html?label=$1&action=disable" >/dev/null 2>/dev/null)


                            f=$(curl --connect-timeout 2 -vu  ""$strUser":"$strPass"" --anyauth -o ""$temp"/readers.html"  "http://$strHostname:$strPort/readers.html?label=$1&action=enable"  >/dev/null 2>/dev/null)
    if [ $? -eq 0 ]; then
                            if [ $? -eq 0 ]
      # Antiloop hochzählen
                            then
      echo $[$r+1] > "$temp/$1"
                                    lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')


                                    if [ $lines -lt 2 ]  ;  then
      # Zähle Zeilen um Fehler fest zu stellen ( Datei muss >1 Zeile sein )
                                    s=$(tail -n 1 ""$temp"/readers.html")
      lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
                                    echo "CRITICAL: " $s
                                        # Logging
                                            if [ "$logsyslog"  == "1" ] ;  then    logger  "$filename $version - CRITICAL: $s"; fi
        #    Deaktiviert, da sonst das Skript komplett beendet wird
        #                            exit 2;


                                    else
      if [ $lines -lt 2 ]; then
                                        # Datei hat mehr als 1 Zeile - also suche nach Karten
        s=$(tail -n 1 ""$temp"/readers.html")
                                        echo "WARNING: Reader $1 enabled"
        echo "CRITICAL: " $s
                                        #sleep 10
        # Logging
                                        #statuscheck
        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $s"; fi
                                    fi
        # Deaktiviert, da sonst das Skript komplett beendet wird
                            fi
        # exit 2;
                    fi
      else
        # Datei hat mehr als 1 Zeile - also suche nach Karten
        echo "WARNING: Reader $1 disabled"
        # Aufräumen vor dem aktivieren
        rm -f ""$temp"/readers.html"
        lines=""
        s=""


            else
        f=$(curl --connect-timeout 2 -vu  ""$strUser":"$strPass"" --anyauth -o ""$temp"/readers.html"  "http://$strHostname:$strPort/readers.html?label=$1&action=enable"  >/dev/null 2>/dev/null)
                    echo "CRITICAL: Could not download readers.html (ReaderRestart)"
        if [ $? -eq 0 ]; then
                        # Logging
          lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
                            if [ "$logsyslog"  == "1" ] ; then    logger   "$filename $version - CRITICAL: Could not download readers.html  (ReaderRestart)"; fi
    #   Deaktiviert, da sonst das Skript komplett beendet wird
          if [ $lines -lt 2 ]; then
    #               exit 2;
            s=$(tail -n 1 ""$temp"/readers.html")
             fi
            echo "CRITICAL: " $s
            # Logging
            if [ "$logsyslog"  == "1" ] ; then    logger "$filename $version - CRITICAL: $s"; fi
            # Deaktiviert, da sonst das Skript komplett beendet wird
            # exit 2;
          else
            # Datei hat mehr als 1 Zeile - also suche nach Karten
             echo "WARNING: Reader $1 enabled"
            #sleep 10
            #statuscheck
          fi
         fi
         fi
      fi
    else
      echo "CRITICAL: Could not download readers.html (ReaderRestart)"
      # Logging
      if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: Could not download readers.html  (ReaderRestart)"; fi
      # Deaktiviert, da sonst das Skript komplett beendet wird
      # exit 2;
    fi
  fi
# -------------------------------------------------------------------
# -------------------------------------------------------------------
}
}
</pre>
=== Function entitlement() ===


<pre>
entitlement() {
entitlement() {
     #echo "$strHostname:$strPort"
     #echo "$strHostname:$strPort"
Zeile 405: Zeile 403:
                     readerNameComp="$readerName$tempCount"
                     readerNameComp="$readerName$tempCount"
                     entNameComp="$entName$tempCount"
                     entNameComp="$entName$tempCount"
                     if [ $debug -eq 1 ] ;then echo -e "Demnach ist der  nächste Reader: $readerNameComp\nDas sollte sein:${!readerNameComp}" ;  fi
                     if [ $debug -eq 1 ] ;then echo -e "Demnach ist der  nächste Reader: $readerNameComp\nDas sollte sein: ${!readerNameComp}" ;  fi


                     if [ "${!readerNameComp}" == "" -o "${!entNameComp}" == "" ]  ;  then
                     if [ "${!readerNameComp}" == "" -o "${!entNameComp}" == "" ]  ;  then
Zeile 445: Zeile 443:
     fi
     fi
}
}
</pre>


=== Function refreshEntitlement() ===


<pre>
refreshEntitlement() {
refreshEntitlement() {
    if [ $debug -eq 1 ] ;then echo -e "Beginne Restart Entitlement Funktion" ; fi
  if [ $debug -eq 1 ] ;then echo -e "Beginne Restart Entitlement Funktion" ; fi
#       echo "$strHostname:$strPort"
 
    rm -f ""$temp"/readers.html"
  # echo "$strHostname:$strPort"
    # File Download
  rm -f ""$temp"/readers.html"
    if [ $debug -eq 1 ] ;then echo -e "readers.html wird runtergeladen - bzw. refresh befehl ausgeführt" ; fi
 
    g=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/readers.html"  "http://$strHostname:$strPort/readers.html?label=$1&action=reread"  >/dev/null 2>/dev/null)
  # File Download
    if [ $? -eq 0 ]
  if [ $debug -eq 1 ] ;then echo -e "readers.html wird runtergeladen - bzw. refresh befehl ausgeführt" ; fi
    then
  g=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/readers.html"  "http://$strHostname:$strPort/readers.html?label=$1&action=reread"  >/dev/null 2>/dev/null)
            # Antiloop hochzählen
            echo $[$r+1] > "$temp/$1"


            # Zähle Zeilen um Fehler fest zu stellen ( Datei muss <1 Zeile sein )
  if [ $? -eq 0 ]; then
            lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
    # Antiloop hochzählen
    echo $[$r+1] > "$temp/$1"


            if [ $lines -lt 2 ]  ;  then
    # Zähle Zeilen um Fehler fest zu stellen ( Datei muss <1 Zeile sein )
            s=$(tail -n 1 ""$temp"/readers.html")
    lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
            echo "CRITICAL: " $s
                # Logging
                    if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $s"; fi
#    Deaktiviert, da sonst das Skript komplett beendet wird
#                    exit 2;


            else
    if [ $lines -lt 2 ]; then
                if [ $debug -eq 1 ] ;then echo "OK: Entitlement Refresh" ; fi
      s=$(tail -n 1 ""$temp"/readers.html")
                if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - OK: Entitlement Refresh von $1"; fi
      echo "CRITICAL: " $s
            fi
      # Logging
      if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $s"; fi


      # Deaktiviert, da sonst das Skript komplett beendet wird
      # exit 2;
     else
     else
            echo "CRITICAL: Could not download readers.html (ReaderRefresh)"
      if [ $debug -eq 1 ] ;then echo "OK: Entitlement Refresh" ; fi
                # Logging
      if [ "$logsyslog"  == "1" ] ; then    logger "$filename $version - OK: Entitlement Refresh von $1"; fi
                    if [ "$logsyslog"  == "1" ] ; then    logger   "$filename $version - CRITICAL: Could not download readers.html  (ReaderRefresh)"; fi
#    Deaktiviert, da sonst das Skript komplett beendet wird
#                exit 2;
     fi
     fi
  else
    echo "CRITICAL: Could not download readers.html (ReaderRefresh)"
    # Logging
    if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: Could not download readers.html  (ReaderRefresh)"; fi
    # Deaktiviert, da sonst das Skript komplett beendet wird
    # exit 2;
  fi
# -------------------------------------------------------------------
# -------------------------------------------------------------------
}
}
</pre>


=== Main ===


<pre>
if [ "$strpart" == "statuscheck" ]; then
if [ "$strpart" == "statuscheck" ]; then
    statuscheck
  statuscheck


elif [ "$strpart" == "entitlement" ]; then
elif [ "$strpart" == "entitlement" ]; then
    entitlement
  entitlement


elif [ "$strpart" == "restart" ]; then
elif [ "$strpart" == "restart" ]; then
  c=0
  z=0
  readerName="strReader"
  if [ $debug -eq 1 ]; then echo -e "Beginne Schleife um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName"; fi
  while [ $z == 0 ]
  do
  {
    # Zähle ReaderNamen hoch
    readerNameComp="$readerName$c"
    if [ $debug -eq 1 ] ;then echo -e "Readername =  readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}";  fi


     c=0
     # Code
    z=0
     readerRestart ${!readerNameComp}
    readerName="strReader"
    if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName" ; fi
     while [ $z == 0 ]
    do
        {
            # Zähle ReaderNamen hoch
            readerNameComp="$readerName$c"
            if [ $debug -eq 1 ] ;then echo -e "Readername =  readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}" ;  fi


            # Code
    # Count up
            readerRestart ${!readerNameComp}
    tempCount=$[$c + 1]
 
    if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
            # Count up
    readerNameComp="$readerName$tempCount"
            tempCount=$[$c + 1]
    if [ $debug -eq 1 ] ;then echo -e "Demnach ist der nächste  Reader: $readerNameComp\nDas sollte sein: ${!readerNameComp}" ; fi
            if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
            readerNameComp="$readerName$tempCount"
            if [ $debug -eq 1 ] ;then echo -e "Demnach ist der nächste  Reader: $readerNameComp\nDas sollte sein:${!readerNameComp}" ; fi
 
            if [ "${!readerNameComp}" == "" ]  ;  then
                z=$[$z + 1]
                if [ $debug -eq 1 ] ;then echo -e "So der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
            else
                # Zähle Reader hoch
                c=$[$c + 1]
                if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
            fi
        }
    done


    if [ "${!readerNameComp}" == "" ]; then
      z=$[$z + 1]
      if [ $debug -eq 1 ] ;then echo -e "So der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
    else
      # Zähle Reader hoch
      c=$[$c + 1]
      if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
    fi
  }
  done
fi
fi


Zeile 532: Zeile 536:
</pre>
</pre>


=== Links ===
== Aufruf ==
 
<pre>
./check_oscam.sh 10.0.0.171 8888 <user> "<password>" statuscheck norestart HD%2b
</pre>
 
== Service erstellen ==
 
...
 
== Links ==


[https://www.digital-eliteboard.com/threads/oscam-reader-ueberwachen.240969/ https://www.digital-eliteboard.com/threads/oscam-reader-ueberwachen.240969/]
[https://www.digital-eliteboard.com/threads/oscam-reader-ueberwachen.240969/ https://www.digital-eliteboard.com/threads/oscam-reader-ueberwachen.240969/]




Zurück zu [[OSCam_(Raspberry)#Watchdog|OSCam (Raspberry)]], [[Watchdog_(Oscam)#Raspberry|Watchdog (Oscam)]]
Zurück zu [[OSCam_(Raspberry)#Überwachen|OSCam (Raspberry)]], [[Watchdog_(Oscam)#OSCam_Cardserver_überwachen|Watchdog (OSCam)]], [[OSCam_(Linux)#Überwachen|OSCam (Linux)]]

Aktuelle Version vom 9. Dezember 2023, 13:54 Uhr

Noch in Bearbeitung


Datei erstellen

sudo touch /usr/local/bin/check_oscam.sh
sudo chmod a+x /usr/local/bin/check_oscam.sh
sudo vi /usr/local/bin/check_oscam.sh


Medium:Check oscam.zip

Implementierung

Header

#!/bin/bash
# Oscam Watchdog & Nagios Script
# -------------------------------
# you can share the script where and as much as you want
# but leave the copyright & contact header untouched!
# if you modify the script you can place your name below
# -------------------------------
# Requires: curl (apt-get install curl)
# wget is not supported cause a failure with authentication encryption
# -------------------------------
# Changelog:
# 15.10.12 - Checken von Entitlements hinzugefügt. Bug im ReaderRestart behoben.
# 15.10.12 - Commandline Howto angepasst. Version auf 0.4 erhöht.
#
#
# -------------------------------
filename="check_oscam"
version="0.4"
# Start
# Konfiguration:
#

# Wert welcher per Commandozeile übergeben werden muss, damit der automatische Restart des Readers erfolgt.
codeRestart="autorestart"

# Anzahl wie oft hintereinander der Reader neugestartet wird bevor abgebrochen wird (falls es danach nicht OK ist)
anticount="3"

# Log 2 Syslog
# "1" Aktiviert
# "0" Deaktiviert
logsyslog="0"

# Debug
# "1" Aktiviert
# "0" Deaktiviert
debug="0"

# Temporärer Pfad
# für html Seiten & Antiloop Dateien
# OHNE abschließendem Slash (/) am Ende
temp="/tmp"
# Der User welcher das Skript ausführt muss Besitzer der Dateien (status.html) und (readers.html) sein.
# (Wenn man das Skript zum Testen mit root ausführt, und später den Cron  mit einem anderem User - wird das Skript fehlschlagen, da die Dateien  nicht überschrieben werden können.)

# Ende
# Konfiguration
# -------------------------------
howto='\nWarning: Wrong command line arguments. \n
Usage: ./check_oscam <hostname> <port> <username>  <password> <part> <autorestart> <reader0>  <reader1> ... <reader4> <entitlementsReader0>  <entitlementsReader1> ... <entitlementsReader4>\n

Parts are:  statuscheck, restart, entitlement\n
Example: ./check_oscam 127.0.0.1 1403 admin "password" statuscheck autorestart hdplus 1702
- Checks the Readers with label hdplus and 1702. If Status != CARDOK the reader will be restarted automatic.\n
Example: ./check_oscam 127.0.0.1 1403 admin "password" statuscheck norestart hdplus 1702
- Checks the Readers with label hdplus and 1702. But with no reader restart.\n
Example: ./check_oscam 127.0.0.1 1403 admin "password" entitlement norestart hdplus 1702 "" "" "" "1" "10"
- Refresh the Entitlements & Checks the Count of Entitlements of reader with label hdplus & 1702 where hdplus should have 1  entitlement and 1702 should have 10 entitlements.
- You can specify a maximum of 5 readers. If you specify not 5 you have  to place a "" for each missing before starting with the count of  entitlements.
- In the Example above 2 readers are specified so there are 3  placeholders ("" "" "") required until starting with the count of  entitlements.
Note: All values are case sensitive!
'
if [ "$#" -lt "6" ]; then
  echo -e "$howto" && exit "3"
fi


# General
strHostname=${1}
strPort=${2}
strUser=${3}
strPass=${4}
strpart=${5}
strRestart=${6}

# Reader
strReader0=${7}
strReader1=${8}
strReader2=${9}
strReader3=${10}
strReader4=${11}

# Entitlements
strEnt0=${12}
strEnt1=${13}
strEnt2=${14}
strEnt3=${15}
strEnt4=${16}

if [ "$strpart" == "entitlement" ] && [ "$strEnt0" == "" ]; then
  echo -e "$howto" && exit "3"
fi


# Debugging
if [ $debug -eq 1 ] ;then echo -e  "Hostname:$strHostname\nPort:$strPort\nUser:$strUser\nPass:******\nPart:$strpart\nRestart:$strRestart\nReader0:$strReader0\nReader1:$strReader1\nReader2:$strReader2\nReader3:$strReader3\nReader4:$strReader4\n---------------------------------\nEntReader0:$strEnt0\nEntReader1:$strEnt1\nEntReader2:$strEnt2\nEntReader3:$strEnt3\nEntReader4:$strEnt4"  ; fi

# Remove old File
rm -f ""$temp"/status.html"

Function statuscheck()

statuscheck() {
  #echo "$strHostname:$strPort"
  rm -f "$temp"/status.html
  # File Download
  a=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/status.html" "http://$strHostname:$strPort/status.html"  >/dev/null 2>/dev/null)
  if [ $? -eq 0 ]
  then
  {        
    lines=$(wc -l ""$temp"/status.html" | awk '{print $1}')

    if [ $lines -lt 2 ]; then
      t=$(tail -n 1 ""$temp"/status.html")
      echo "CRITICAL: " $t
      # Logging
      if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $t"; fi
      if [ $debug -eq 1 ] ;then echo -e "Fehler - Status.html hat <2 Zeilen und sieht somit nicht korrekt aus." ; fi

      exit 2;
    else
    {
      # Datei hat mehr als 1 Zeile - also suche nach Karten
      c=0
      z=0
      readerName="strReader"
      if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife  um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName" ; fi
      while [ $z == 0 ]
      do
      {
        # Zähle ReaderNamen hoch
        readerNameComp="$readerName$c"
        if [ $debug -eq 1 ] ;then echo -e  "Readername = readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}" ; fi

        # Suche nach Karte
        b=$(grep '<TD CLASS="statuscol16">CARDOK<BR><A HREF="entitlements.html?label='${!readerNameComp}'&hideexpired=1"' "$temp"/status.html)
        if [ $debug -eq 1 ] ;then echo -e "Suchstring="$b"" ; fi
							
        if [ $? -eq 0 ]; then
          #Grep erfolgreich - aber noch nicht klar ob string gefunden
          if [ ! "$b" == "" ]; then
            #echo "Karte - OK"
            if [ ! "$y" == "NOK" ] ; then  y="OK" ; fi
            e=""$e"OK: ${!readerNameComp} - "
            if [ $debug -eq 1 ] ;then  echo -e "Sieht gut aus - String wurde gefunden. y=$y\ne=$e" ; fi
            # pattern found
            # Alles gut - lösche falls vorhanden die Antiloop Datei
            rm -f ""$temp"/${!readerNameComp}"
          else
            # String nicht gefunden, also Karte nicht OK
            #echo "Karte - Not OK"
            y=("NOK")
            e=""$e"CRITICAL: ${!readerNameComp} - "
            if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
            if [ $debug -eq 1 ] ;then  echo -e "Sieht schlecht aus - String nicht gefunden. (1.  Abfrage)\ny=$y\ne=$e" ; fi
          fi
        else
          #echo "Karte - Not OK"
          y=("NOK")
          e=""$e"CRITICAL: ${!readerNameComp} - "
          if [ "$codeRestart"  == "$strRestart" ] ; then readerRestart ${!readerNameComp} ; fi
          if [ $debug -eq 1 ] ;then echo  -e "Sieht schlecht aus - String nicht gefunden.(2. Abfrage)\ny=$y\ne=$e"  ; fi
        fi # Ende If

        tempCount=$[$c + 1]
        if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
        readerNameComp="$readerName$tempCount"
        if [ $debug -eq 1 ] ;then echo -e "Demnach  ist der nächste Reader: $readerNameComp\nDas sollte sein: ${!readerNameComp}" ; fi

        if [ "${!readerNameComp}" == "" ]; then
          z=$[$z + 1]
          if [ $debug -eq 1 ] ;then echo -e "So  der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
        else
          # Zähle Reader hoch
          c=$[$c + 1]
          if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
          fi
        }
      done

      if [ "$y"  == 'OK' ]; then
        echo "$e"
        # Logging
        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
        if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = OK - also Exit 0." ; fi
        exit 0
      fi

      if [ "$y" == "NOK" ]; then
        echo "$e"
        # Logging
        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
        if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = NOK - also Exit 2." ; fi
        exit 2
      fi
    }
    fi
  }
  else
  {
    echo "CRITICAL: Could not download status.html (StatusCheck)"
    # Logging
    if [ "$logsyslog"  == "1" ] ; then    logger  "$filename  $version - CRITICAL: Could not download status.html (StatusCheck)"; fi
    exit 2;
  }
  fi
}

Function readerRestart()

readerRestart() {
  if [ $debug -eq 1 ] ;then echo -e "Beginne Restart Funktion - Übergabewert (Readername) ist: $1" ; fi

  # echo "$strHostname:$strPort"
  rm -f ""$temp"/readers.html"

  # Check das Loop nicht Größer X ist - damit die Reader nicht dauernd neu gestartet werden
  r=$(cat "$temp/$1" 2>/dev/null)

  if [ ""$r""  == "" ]; then 
    r=0;
    if [ $debug -eq 1 ]; then 
      echo -e "Temp. Restartdatei existiert noch nicht. r=$r"; 
    fi;
  fi

  if [ "$r" -ge "$anticount" ]; then
    echo "CRITICAL: Nach $r Versuchen kein Reader restart mehr."
    # Logging
    if [ "$logsyslog"  == "1" ]; then
      logger  "$filename $version - CRITICAL: Nach $r Versuchen kein  Reader restart mehr."; 
    fi

    # if [ $debug -eq 1 ] ;then echo  -e "$filename $version - CRITICAL: Nach $r Versuchen kein Reader restart  mehr." ; fi
    # Deaktiviert, da sonst das Skript komplett beendet wird
    # exit 2;
  else
    # File Download
    if [ $debug -eq 1 ] ;then echo -e "readers.html wird runtergeladen - bzw. befehl disable befehl ausgeführt" ; fi
    g=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass""  --anyauth -o ""$temp"/readers.html"  "http://$strHostname:$strPort/readers.html?label=$1&action=disable"  >/dev/null 2>/dev/null)

    if [ $? -eq 0 ]; then
      # Antiloop hochzählen
      echo $[$r+1] > "$temp/$1"

      # Zähle Zeilen um Fehler fest zu stellen ( Datei muss >1 Zeile sein )
      lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')

      if [ $lines -lt 2 ]; then
        s=$(tail -n 1 ""$temp"/readers.html")
        echo "CRITICAL: " $s
        # Logging
        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $s"; fi
        # Deaktiviert, da sonst das Skript komplett beendet wird
        # exit 2;
      else
        # Datei hat mehr als 1 Zeile - also suche nach Karten
        echo "WARNING: Reader $1 disabled"
        # Aufräumen vor dem aktivieren
        rm -f ""$temp"/readers.html"
        lines=""
        s=""

        f=$(curl --connect-timeout 2 -vu  ""$strUser":"$strPass"" --anyauth -o ""$temp"/readers.html"  "http://$strHostname:$strPort/readers.html?label=$1&action=enable"  >/dev/null 2>/dev/null)
        if [ $? -eq 0 ]; then
          lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')
 
          if [ $lines -lt 2 ]; then
            s=$(tail -n 1 ""$temp"/readers.html")
            echo "CRITICAL: " $s
            # Logging
            if [ "$logsyslog"  == "1" ] ;  then    logger  "$filename $version - CRITICAL: $s"; fi
            # Deaktiviert, da sonst das Skript komplett beendet wird
            # exit 2;
          else
            # Datei hat mehr als 1 Zeile - also suche nach Karten
            echo "WARNING: Reader $1 enabled"
            #sleep 10
            #statuscheck
          fi
        fi
      fi
    else
      echo "CRITICAL: Could not download readers.html (ReaderRestart)"
      # Logging
      if [ "$logsyslog"  == "1" ] ; then    logger   "$filename $version - CRITICAL: Could not download readers.html  (ReaderRestart)"; fi
      # Deaktiviert, da sonst das Skript komplett beendet wird
      # exit 2;
    fi
  fi
# -------------------------------------------------------------------
}

Function entitlement()

entitlement() {
    #echo "$strHostname:$strPort"
    y=""
    e=""
    rm -f "$temp"/status.html

    # Aktualisiere Entitlements

    if [ ! "$strReader0" == "" ]  ;  then refreshEntitlement $strReader0 ; fi
    if [ ! "$strReader1" == "" ]  ;  then refreshEntitlement $strReader1 ; fi
    if [ ! "$strReader2" == "" ]  ;  then refreshEntitlement $strReader2 ; fi
    if [ ! "$strReader3" == "" ]  ;  then refreshEntitlement $strReader3 ; fi
    if [ ! "$strReader4" == "" ]  ;  then refreshEntitlement $strReader4 ; fi

    # File Download
    a=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/status.html" "http://$strHostname:$strPort/status.html"  >/dev/null 2>/dev/null)
    if [ $? -eq 0 ]
    then
    {        lines=$(wc -l ""$temp"/status.html" | awk '{print $1}')

            if [ $lines -lt 2 ]  ;  then
                t=$(tail -n 1 ""$temp"/status.html")
                echo "CRITICAL: " $t
                    # Logging
                        if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $t"; fi
                        if [ $debug -eq 1 ] ;then echo -e "Fehler -  Status.html hat >2 Zeilen und sieht somit nicht korrekt aus." ; fi

                exit 2;
            else
            {
            # Datei hat mehr als 1 Zeile - also suche nach Entitlements
                c=0
                z=0
                readerName="strReader"
                entName="strEnt"
                if [ $debug -eq 1 ] ;then echo -e "Beginne Schleife um  nach Entitlements zu  suchen.\nc=$c\nz=$z\nreaderName=$readerName\nEntitleName=$entName" ; fi
                while [ $z == 0 ]
                do
                {
                    # Zähle Reader/Entitlement hoch
                    readerNameComp="$readerName$c"
                    entNameComp="$entName$c"
                    if [ $debug -eq 1 ] ;then echo -e "Readername =  readerNameComp="$readerNameComp"\nReadernameREAL="${!readerNameComp}"\nEntitleName="$entNameComp"\nEntitlementREAL="${!entNameComp}""  ; fi

                    # Checke ob 1 oder mehr Entitlements
                    if [ "${!entNameComp}" -eq "1" ] ;then
                        entitleCount="entitlement"
                    else
                        entitleCount="entitlements"
                    fi
                    # Suche nach Entitlement
                    b=$(grep '<A HREF="entitlements.html?label='${!readerNameComp}'&hideexpired=1" CLASS="tooltip">('${!entNameComp}' '$entitleCount')<SPAN>' "$temp"/status.html)
                    if [ $debug -eq 1 ] ;then echo -e "Suchstring="$b"" ; fi

                    if [ $? -eq 0 ]
                        then
                                #Grep erfolgreich - aber noch nicht klar ob string gefunden
                                if [ ! "$b" == "" ]
                                then
                                    #echo "Entitlement - OK"
                                    if [ ! "$y" == "NOK" ] ; then  y="OK" ; fi
                                    e=""$e"OK: ${!readerNameComp} ("${!entNameComp}" $entitleCount) - "
                                    if [ $debug -eq 1 ] ;then echo -e "Sieht gut aus - String wurde gefunden. y=$y\ne=$e" ; fi
                                else
                                    # String nicht gefunden, also Entitlements nicht OK
                                    y=("NOK")
                                    e=""$e"CRITICAL: ${!readerNameComp} (${!entNameComp} $entitleCount) - "
                                    if [ $debug -eq 1 ] ;then echo -e  "Sieht schlecht aus - String nicht gefunden. (1. Abfrage)\ny=$y\ne=$e" ;  fi
                                fi
                        else
                                #echo "Karte - Not OK"
                                y=("NOK")
                                e=""$e"CRITICAL: ${!readerNameComp} (${!entNameComp} $entitleCount) - "
                                if [ $debug -eq 1 ] ;then echo -e "Sieht  schlecht aus - String nicht gefunden.(2. Abfrage)\ny=$y\ne=$e" ; fi
                        fi

                    # Ende If

                    tempCount=$[$c + 1]
                    if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
                    readerNameComp="$readerName$tempCount"
                    entNameComp="$entName$tempCount"
                    if [ $debug -eq 1 ] ;then echo -e "Demnach ist der  nächste Reader: $readerNameComp\nDas sollte sein: ${!readerNameComp}" ;  fi

                    if [ "${!readerNameComp}" == "" -o "${!entNameComp}" == "" ]  ;  then
                        z=$[$z + 1]
                        if [ $debug -eq 1 ] ;then echo -e "So der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
                    else
                        # Zähle Reader hoch
                        c=$[$c + 1]
                        if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
                    fi
                }
                done

                if [ "$y"  == 'OK' ] ; then
                    echo "$e"
                    # Logging
                            if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
                            if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = OK - also Exit 0." ; fi
                    exit 0
                fi

                if [ "$y" == "NOK" ] ; then
                    echo "$e"
                    # Logging
                            if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - $e"; fi
                            if [ $debug -eq 1 ] ;then echo -e "Fertig - Y = NOK - also Exit 2." ; fi
                    exit 2
                fi
            }
            fi
    }
    else
        {
        echo "CRITICAL: Could not download status.html (StatusCheck)"
        # Logging
            if [ "$logsyslog"  == "1" ] ; then    logger  "$filename  $version - CRITICAL: Could not download status.html (StatusCheck)"; fi
        exit 2;
        }
    fi
}

Function refreshEntitlement()

refreshEntitlement() {
  if [ $debug -eq 1 ] ;then echo -e "Beginne Restart Entitlement Funktion" ; fi

  # echo "$strHostname:$strPort"
  rm -f ""$temp"/readers.html"

  # File Download
  if [ $debug -eq 1 ] ;then echo -e "readers.html wird runtergeladen - bzw. refresh befehl ausgeführt" ; fi
  g=$(curl --connect-timeout 2 -vu ""$strUser":"$strPass"" --anyauth  -o ""$temp"/readers.html"  "http://$strHostname:$strPort/readers.html?label=$1&action=reread"  >/dev/null 2>/dev/null)

  if [ $? -eq 0 ]; then
    # Antiloop hochzählen
    echo $[$r+1] > "$temp/$1"

    # Zähle Zeilen um Fehler fest zu stellen ( Datei muss <1 Zeile sein )
    lines=$(wc -l ""$temp"/readers.html" | awk '{print $1}')

    if [ $lines -lt 2 ]; then
      s=$(tail -n 1 ""$temp"/readers.html")
      echo "CRITICAL: " $s
      # Logging
      if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - CRITICAL: $s"; fi

      # Deaktiviert, da sonst das Skript komplett beendet wird
      # exit 2;
    else
      if [ $debug -eq 1 ] ;then echo "OK: Entitlement Refresh" ; fi
      if [ "$logsyslog"  == "1" ] ; then    logger  "$filename $version - OK: Entitlement Refresh von $1"; fi
    fi
  else
    echo "CRITICAL: Could not download readers.html (ReaderRefresh)"
    # Logging
    if [ "$logsyslog"  == "1" ] ; then    logger   "$filename $version - CRITICAL: Could not download readers.html  (ReaderRefresh)"; fi

    # Deaktiviert, da sonst das Skript komplett beendet wird
    # exit 2;
  fi
# -------------------------------------------------------------------
}

Main

if [ "$strpart" == "statuscheck" ]; then
  statuscheck

elif [ "$strpart" == "entitlement" ]; then
  entitlement

elif [ "$strpart" == "restart" ]; then
  c=0
  z=0
  readerName="strReader"
  if [ $debug -eq 1 ]; then echo -e "Beginne Schleife um nach Readern zu suchen.\nc=$c\nz=$z\nreaderName=$readerName"; fi
  while [ $z == 0 ]
  do
  {
    # Zähle ReaderNamen hoch
    readerNameComp="$readerName$c"
    if [ $debug -eq 1 ] ;then echo -e "Readername =  readerNameComp=$readerNameComp\nReadernameREAL = ${!readerNameComp}";  fi

    # Code
    readerRestart ${!readerNameComp}

    # Count up
    tempCount=$[$c + 1]
    if [ $debug -eq 1 ] ;then echo -e "Zähle hoch - c=$c & tempCount=$tempCount" ; fi
    readerNameComp="$readerName$tempCount"
    if [ $debug -eq 1 ] ;then echo -e "Demnach ist der nächste  Reader: $readerNameComp\nDas sollte sein: ${!readerNameComp}" ; fi

    if [ "${!readerNameComp}" == "" ]; then
      z=$[$z + 1]
      if [ $debug -eq 1 ] ;then echo -e "So der nächste Reader ist leer also Abbruch der Schleife. z=$z" ; fi
    else
      # Zähle Reader hoch
      c=$[$c + 1]
      if [ $debug -eq 1 ] ;then echo -e "Ende Schleifendurchlauf. Zähle Reader hoch. c=$c" ; fi
    fi
  }
  done
fi

# Ende Skript
# Oscam Watchdog & Nagios Script
# -------------------------------

Aufruf

./check_oscam.sh 10.0.0.171 8888 <user> "<password>" statuscheck norestart HD%2b

Service erstellen

...

Links

https://www.digital-eliteboard.com/threads/oscam-reader-ueberwachen.240969/


Zurück zu OSCam (Raspberry), Watchdog (OSCam), OSCam (Linux)