This all works fine as a script, however when compiled as a service, it fails to detect failures

So, in the simple example that you showed, the service runs the "#something GOOD" block, and then you find out that nothing was appended to the file -- is that it?

Why not include a check for file size before and after you have opened the file, appended data, and closed it? e.g.:

my $refsize = (-s $filename); my $appendstr = "12345678\015\012"; if ( open( FH, ">>$filename" )) { print FH $appendstr; close FH; if (-s $filename != $refsize + length( $appendstr ) { warn "open succeeded on $filename, but write failed"; # something bad } else { # something good } } else { # a different something bad }
(Or does -s not work either?) I suppose you've tried "-M" already? (check the age of the file, before and after appending data)

Granted, having the script behave differently in different contexts is a bad deal, but being at a loss about how to fix that, I would keep looking for another way of performing the intended server test that just gets around the problem.

(I assume the test must also include reading the file back at some point, to determine the last time stamp written to the file. Why not include that as a condition for entering the "something GOOD" block?)


In reply to Re: file poll script by graff
in thread file poll script by northen.soul

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.