1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

OSCAM Watchdog script

Discussion in 'Tomato Firmware' started by kyrios, Apr 5, 2013.

  1. kyrios

    kyrios Serious Server Member

    Anyone have watchdog script for OSCAM into Tomato?
    Oscam has been running fine into my Tomato (RT-N16).
    But sometimes, the Reader need to be restarted.

    Here's the image when Reader is ERROR.
    [​IMG]
    I have seeked around the net about solution but seems no script for Tomato.
    OK, I have an idea about retrieving the output (Reader error or not)
    without log file being activated (/var/log/oscam.log)
    [​IMG]

    Code:
    http://$admin:$passw@$IP:$Port/oscamapi.html?part=status
    When Reader is OK, output is like this:
    [​IMG]

    When Reader is Error, output is like this:
    [​IMG]

    Maybe involving command like count, tail, grep "ERROR" | wc -l
    I just do not know how to write such script. I'm blind about UNIX command.

    All I know is only the command to restart Reader.
    Code:
    http://$admin:$passw@$IP:$Port/oscamapi.html?part=status&label=$Reader&action=restart
    Anyone can write me the script, please?
    Administration => Scheduler => Custom1 => Every 5 Minutes
     
  2. kyrios

    kyrios Serious Server Member

    Just found out curl command not found in busybox 1.20.2 (by Shibby).
    Firmware is Toastman 502.1 VLAN-Lite.
    Any idea?
     
  3. koitsu

    koitsu Network Guru Member

    curl is a very large application/library that relies on other libraries -- it will never be provided by any firmware given the large amount of disk it requires.

    Can you explain exactly what you're trying to do that requires curl? Possibly there are other methods of accomplishing what you need with the built-in utilities sans curl.
     
  4. kyrios

    kyrios Serious Server Member

    I found watchdog script in spanish. It's for PC, Dreambox or something.
    This script required the log must be enabled.
    Code:
    #!/bin/sh
    # script para reiniciar un READER de OSCAM con el error que querais que cuando ocurra se reinicie
    ################### Insertar los valores dependiendo de vuestro deco. #####################
    LOG=/var/log/oscam.log
    lineas=23
    IP=192.168.1.1
    Port=666
    Reader=sabrina
    user=user
    pass=pass
    tiempo=10
    error="status not ok"
    #################################################################################
     
     
    while :
            do
            tiempo=$tiempo
            count=`tail -n $lineas $LOG | grep "$error" | wc -l`
            if [ "$count" -gt "0" ]
            then
            echo "Reader $Reader"
            curl --digest -u"$user:$pass" "http://$IP:$Port/oscamapi.html?part=status&label=$Reader&action=restart" >> /dev/null 2>&1
            tiempo=10
            fi
    done
    I tested it, the curl command does not work in Tomato.
    I would like to remove tiempo variable and replace it with Scheduler feature fromTomato.
     
  5. koitsu

    koitsu Network Guru Member

    What is OSCAM? Is it a daemon/piece of software that runs on your router that listens on its own port/has its own web interface? It looks like it is.

    In that case, why not just restart the daemon/program rather than submitting some wonky "restart request" through an HTTP request?

    If you can educate me about the software I can tell you how to automatically restart the thing without reliance on curl or whatever else.

    P.S. -- Whoever wrote that script has no idea what they're doing. There are so many errors in it. So so so many. That script will also cause your router to take up 100% CPU time.
     
  6. kyrios

    kyrios Serious Server Member

    OSCAM is software for cardsharing (PayTV).
    OSCAM can be as server. using card reader (Irdeto) and then original card (genuine card) must be inserted.
    OSCAM can also be set as client. Me, since does not have original card, install setup it as client.
    OSCAM client request (encrypted) ECM (about 2-20kb) to server, and server reply back with decypted ECM.
    The ECM request is about each 2-4 seconds, never count.
    Then the TV broadcast can be displayed properly (not scrambled) on TV :)
    That is only rough explanation about OSCAM, far more correct.

    BTW, talking about log file (oscam.log) here's the log when Reader service is perfect.
    I just cut and paste the latest lines (last lines).
    Code:
    013/04/06 16:34:40 2005 p connecting to reader1.reader1.com
    2013/04/06 16:34:40 2005 p tiket.njoydream.com: resolved ip=220.220.220.220
    2013/04/06 16:34:52 1406 c client1 (09C1&000000/1EDE/AB:3443): found (433 ms) by reader1 (of 1 avail 1)
    2013/04/06 16:35:02 1406 c client1 (09C1&000000/1EDE/AB:253A): found (721 ms) by reader1 (of 1 avail 1)
    2013/04/06 16:35:13 1406 c client1 (09C1&000000/1EDE/AB:212E): found (1003 ms) by reader1 (of 1 avail 1)
    2013/04/06 16:35:23 1406 c client1 (09C1&000000/1EDE/AB:B8B4): found (912 ms) by reader1 (of 1 avail 1)
    2013/04/06 16:35:23 1406 c client1 (09C1&000000/1EDE/AB:3CD0): found (512 ms) by reader1 (of 1 avail 1)
    2013/04/06 16:35:32 1406 c client1 (09C1&000000/1EDE/AB:8D04): found (682 ms) by reader1 (of 1 avail 1)

    And here's 2 examples when reader is error.
    Code:
    2013/04/05  1:06:06    1005 p connecting to reader2.reader2.net
    2013/04/05  1:06:07    1005 p connect(fd=21) failed: (errno=145 Connection timed out)
    2013/04/05  1:06:07    1005 p reader2 network connect error!
    2013/04/05  1:06:07    2006 c client1 (09C1&000000/1DB4/AB:486F): rejected reader peer (624 ms) by reader2 (of 1 avail 1)
    2013/04/05  1:06:07    2006 c client1 (09C1&000000/1DB4/AB:486F): not found (0 ms) by reader2 (of 1 avail 1)
    2013/04/05  1:06:07    2006 c client1 (09C1&000000/1DB4/AB:486F): not found (0 ms) by reader2 (of 1 avail 1)
    2013/04/05  1:06:07    2006 c client1 (09C1&000000/1DB4/AB:486F): not found (0 ms) by reader2 (of 1 avail 1)
    2013/04/05  1:06:07    2006 c client1 (09C1&000000/1DB4/AB:486F): not found (0 ms) by reader2 (of 1 avail 1)
    2013/04/05  1:06:07    2006 c client1 (09C1&000000/1DB4/AB:486F): not found (0 ms) by reader2 (of 1 avail 1)
    This problem may caused by client side. Reader function not work properly due to
    OSCAM service executed premature or something else.
    OSCAM service well known to be executed latest, after all tomato services all are executed.
    We usually have to add sleep 5 at Init script (Tomato) before execute it in order OSCAM service runs correctly.

    Here's another log file when reader is error.
    Code:
    2013/04/06 16:34:36    1005 p connecting to reader2.reader2.net
    2013/04/06 16:34:36    1005 p cccam(r) reader2:  connection closed by remote server
    2013/04/06 16:34:36    1005 p connecting to reader2.reader2.net
    2013/04/06 16:34:36    1005 p cccam(r) reader2:  connection closed by remote server
    2013/04/06 16:34:37    1005 p connecting to reader2.reader2.net
    2013/04/06 16:34:37    1005 p cccam(r) reader2:  connection closed by remote server
    2013/04/06 16:34:37    1005 p connecting to reader2.reader2.net
    2013/04/06 16:34:37    1005 p cccam(r) reader2:  connection closed by remote server
    This problem caused by server side, not our client side. The reader service (of oscam server) or oscam server itself need to be restarted.
    We can do nothing as this is server fault side.

    OK Koitsu, back to topic.
    the error variable, we can use not found or not found (0 ms) as variable.

    To restart reader service, we can use this:
    Code:
    http://$user:$passw@$IP:$Port/status.html?action=restart&label=$reader
    Or we may force OSCAM to restart:
    Code:
    Sorry, I do not know the code. It's JS
     
  7. koitsu

    koitsu Network Guru Member

    Thank you for the information -- it's good info, but it's not exactly what I was looking for. :-( I could have been more clear in what I was asking, my apologies.

    It looks like OSCAM runs on the router itself, because some piece of software listens on TCP port 666 (according to your script) (BTW, port 666 is registered per IANA as dedicated to Doom (the game) servers, so you may want to use a different port that isn't conflicting with an IANA-registered one. Port 28, for example, is available)

    So here's my question:

    Why can't your above script (the one that I said takes 100% CPU time), instead of using curl or talking via HTTP to restart the server, simply restart the daemon itself? Something like kill -TERM `pidof oscam` ; sleep 1 ; oscam would restart the daemon, assuming it's program name/process name is called oscam.

    You should also change that above script (that looks to see if there's a timeout) to use sleep so that it isn't constantly taking up 100% CPU.
     

Share This Page