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.:
(Or does -s not work either?) I suppose you've tried "-M" already? (check the age of the file, before and after appending data)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 }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |