First of all Thank you very much for your reply

The most frustrated thing that can happen to a developer did happen: I was trying to debug the error following your advise (checking the value of the signal to verify whether if the script completed, printing the content of the output @flush)... When the error disappeared. The machine is the same and I have only introduced debugging lines, so now I have the unsettling feeling that my code hides a spurious bug.

But at least it is safer and it will be easier to find what is going on with the lines you suggested the next time it fails :)

I also realised thanks to your observations that it is useless and even redundant to execute start before the script, since start is precisely the executable file that sets the value of $UNXEXSCRIPT, it's own path.

The script iax_0tasksimp.pl is simply a launcher of script with a timeout and check of return code and output.

The script iax_0taskchklog.pl is a launcher of script with a timeout check of return code, output and line in a log.

These lauchers do verify the whole $??, and I did the timeout with a countdown child and interruption to the father, who kills the child performing the main task (but not the grandchildren, that is tricky for my level). Surely perl has a built-in library to do the same (launching a script with a timeout/kill and return code verification).

The script that encapsulates them just launch these "launchers" sequentially. They are generic mini tools that I reuse for multiple purposes.

Just in case you are curious, in this case I am using these little tools to redefine a Tomcat instance, for that I have a perl script that launchs sequentially:

- 1) iax_0taskchklog.pl launching a certain script tbtom.sh stop_all /users/iax00/exploit/data/tom85/admin_portal.xml, with a timeout of 15 seconds, expecting it to return a code 0 and looking for the message "Command successful. Status: 0." to appear in its log. If it is successful, it goes on, if not, it aborts.

- 2) iax_0taskchklog.pl launching tbtom.sh delete_all /users/iax00/exploit/data/tom85/admin_portal.xml, with a timeout of 15 seconds, expecting it to return a code 0 and looking for the message "Command successful. Status: 0." to appear in its log. If it is successful, it goes on, if not, it aborts.

- 3) iax_0taskchklog.pl launching tbtom.sh define_all /users/iax00/exploit/data/tom85/admin_portal.xml, with a timeout of 15 seconds, expecting it to return a code 0 and looking for the message "Command successful. Status: 0." to appear in its log. If it is successful, it goes on, if not, it aborts.

- 4) iax_0taskchklog.pl launching tbtom.sh start_all /users/iax00/exploit/data/tom85/admin_portal.xml, with a timeout of 15 seconds, expecting it to return a code 0 and looking for the message "Command successful. Status: 0." to appear in its log. If it is successful, it goes on, if not, it aborts.

- Finally, iax_0tasksimp.pl launching a verifTomcatAdminPortal.sh, which returns 0 if there is one and only one instance tomcat called admin_portal running (I do this with a simple ps | grep ), and 5 if it fails. The problem was that there was no tomcat running, and the verification was still ok, manually, my iax_0tasksimp.pl launching verifTomcatAdminPortal.sh returned 5, but within the sequence of tasks, it said the return code was 0.

The previous steps tbtom.sh give all an OK and they should not, they should return an error at some point, as the tomcat instance has not started, but I have checked that they indeed return 0, and its log has a happy final line "Command successful. Status: 0." at each execution. tbtom.sh is not my script tho, and I am not allowed to touch it, just to report its malfunction (the same way that I expect that my colleagues report my bugs if they use my launchers. And I don't mind at all if they touch them, although generally they do not have the time :)


In reply to Re^2: problem retrieving return code of an execution with back ticks (updated) by luxAeterna
in thread problem retrieving return code of an execution with back ticks by luxAeterna

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.