hi Pedro,

a followup to your question -- instead of using a Perl based wrapper that
was described in the previous post, there is a simpler solution. If you are
running SEC on a recent Linux distribution, you can use the 'timeout'
command line tool which allows for limiting the run time of a command line
and ending it with a user defined signal. For example, consider the
following 'spawn' action that uses 'timeout' tool for executing /bin/myprog
and terminating it with signal 15 (TERM) if /bin/myprog is still running
after 10 seconds:

action=spawn ( /usr/bin/timeout -s 15 10 /bin/myprog; /bin/echo -e "\nExit
code: $?" )

If 'spawn' is defined in this way, all lines from standard output of
/bin/myprog will be captured by SEC as synthetic events. Also, after
/bin/myprog exits or is terminated by 'timeout' tool, synthetic event "Exit
code: <code>" will be generated for reporting the exit code of /bin/myprog.
Note that if /bin/myprog timed out, 'timeout' tool returns the exit code
124. In order to distinguish synthetic events in a better way from other
similar events, you can use the 'cspawn' action with SEC --intcontexts
command line option for generating events with a custom context. For
example, if you have the following action

action=cspawn TESTPROG (/usr/bin/timeout -s 15 10 /bin/myprog; /bin/echo -e
"\nExit code: $?")

then the following rule will match the synthetic event with the exit code
of /bin/myprog:

type=Single
ptype=RegExp
pattern=^Exit code: (\d+)$
context=TESTPROG
desc=catch the exit code of command
action=logonly Command has terminated with exit code $1

I have also updated the relevant FAQ entry with an example involving the
'timeout' tool: http://simple-evcorr.github.io/FAQ.html#20

kind regards,
risto


Kontakt Risto Vaarandi (<risto.vaara...@gmail.com>) kirjutas kuupƤeval T,
30. juuli 2019 kell 00:50:

> hi Pedro,
>
> these are interesting questions. As for fetching the exit code from spawn,
> SEC does that and produces a warning message if it is non-zero, but there
> is no equivalent to bash $? variable. Firstly, command lines are executed
> asynchronously by spawn, and secondly, many such command lines may be
> running simultaneously. It is therefore difficult to tell which command's
> exit code $? is currently holding. For addressing this issue, it is
> probably best to write a simple wrapper script around the program that
> needs execution, and pass the exit code value to SEC as a synthetic event
> (just like program's standard output is passed). For example, the following
> simple script creates "TEST_EXIT_<code>" synthetic event:
>
> #!/bin/bash
>
> /bin/false
> echo TEST_EXIT_$?
>
> However, running a child process from SEC for at most given number of
> seconds is a trickier issue. Although the spawn action does not have
> parameters for setting this timeout, this task can again be handled with a
> wrapper script, and there is a relevant example in the SEC FAQ:
> http://simple-evcorr.github.io/FAQ.html#20
>
 ...

>
>
_______________________________________________
Simple-evcorr-users mailing list
Simple-evcorr-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users

Reply via email to