script with MULTIPLE conditional execution

  • behappyex

    behappyex - 2010-06-13

    example sfk script with conditional execution:
         file logfilter.txt:
           sfk label checklog
              +tail -follow logfile.txt
              +tee toterm +filter -+error:
              +if "rc>0" call myalert
              +loop +end
           sfk label myalert
              +run -yes "myalert.bat" +end
         sfk script logfilter.txt
            will run myalert.bat whenever errors appear in logfile.txt.

    But how to do it if i have multiple conditions? Is it possible? I tried something like this but it does not work:

           sfk label checklog
              +tail -follow logfile.txt
              +tee toterm +filter -+error:
              +if "rc>0" call myalertError
              +filter -+warning:
              +if "rc>0" call myalertWarning
              +loop +end
           sfk label myalertError
              +run -yes "myalertError.bat" +end
           sfk label myalertWarning
              +run -yes "myalertWarning.bat" +end

    Please help!

  • stahlworks

    stahlworks - 2010-11-13

    The reason why it doesn't work is:

    +filter -+error:

    tells to pass only lines containing "error:".
    If no such lines exist, no text at all will be
    passed further down the command chain.
    Therefore the

    +filter -+warning:

    will receive no text at all, as everything
    was blocked in the previous filter statement.
    (Therefore the "tee" statement before the filter,
    otherwise we would never see any output.)

    Of course it would be good to support multiple if conditions.

    I tried some quick solutions, like adding an option
    to the filter command to pass-through it's text.

    But then, questions arose, like
    - will "+if" receive text or filename data
    - should it forward what kind of data to the
    next command (forwarding should stay flexible,
    not limited to only this example)
    - what when reaching +end, should chain data
    be dumped to terminal or not
    - when calling myalertError, all chain text is lost,
    so it needs some save and restore mechanism
    - should +run within the call modify
    the chain data or not, i.e. should it dump
    command output or status data to the chain
    - can the syntax stay easy with all these requirements

    and that's where i had to stop experimenting, for now.
    Maybe I find a better approach later.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks