script hangs when run from command line and redirecting stdout and stderr to file



when i run this perl script from the command line directly, there is no
problem. when i run it like so:

script.pl > script.log 2>&1 &


....i noticed that script.log ceased being written to after a while--and
not always at the same point.

my script has print statements in it, which should be redirected to
script.log. i tried running the above line a couple of times, and some
of the lines that i printed were cut off in mid-string. i received no
error message though, and when i did a ps -ef | grep script.pl the
process was still running.

one pattern i noticed was that it always stopped after the first
&measure_url_performance was done. this may be because i only ran it
twice this way.

here is a short but (hopefully) complete working script:

#!/usr/bin/perl
use strict; use warnings;
use File::Find;
use Date::Manip;
use Mail::Sender;
use Statistics::Descriptive;
require "tools.pl";


my (
$beginDate,
$numDays,
$chkCount,
$printDate,
$allRecs,
$logDate, # Log Date to look for in the format "YYDDMM", example
030509 for 5/9/03
$avgDuration,
$mailBody,
$maxDuration,
$minDuration,
$noDuration,
$pctile90,
$parseString, # String to look for in the logs. Enclose in
quotes if spaces are included.
$totFiles, # Total number of files reviewed.
$recCount, # Total records found in all files that match the
parseString
$stat, # Statistics::Descriptive object
$yesterday
);

my @one_dirs = glob("/path1");
my @one_urls = ('this/is/a/string');

my @two_dirs = glob("/path2");
my @two_urls = ('this/is/another/string');

measure_url_performance( \@one_urls, \@one_dirs, 1 );
measure_url_performance( \@two_urls, \@two_dirs, 2 );

sub measure_url_performance {
my ($urls_ref, $dirs_ref, $type) = @_;

my @urls = $urls_ref ? @{$urls_ref} : ();
my @dirs = $dirs_ref ? @{$dirs_ref} : ();

my $wanted = get_parse_routine($type);

foreach (@urls) {
$parseString = $_;
print "parseString is -$parseString-\n";
$stat = Statistics::Descriptive::Full->new();
for my $diff ( 0..$numDays ) {
$logDate = UnixDate(DateCalc($beginDate, " + $diff day"),
'%y%m%d');
$printDate = $logDate;
$printDate =~ s/(\d\d)(\d\d)(\d\d)/$2\/$3\/$1/;
$recCount = 0;
print "logDate is -$logDate-\n";
# find( \&process_file, @dirs );
find( $wanted, @dirs );
$allRecs += $recCount;
}
$pctile90 = sprintf( "%.3f", $stat->percentile(90) );
$avgDuration = sprintf( "%.3f",$stat->mean() );
$minDuration = sprintf( "%.3f", $stat->min() );
$maxDuration = sprintf( "%.3f", $stat->max() );
print LOGINCSV
"$parseString,$beginDate,$printDate,$allRecs,$pctile90,$avgDuration,$minDuration,$maxDuration\n";
print "Found $allRecs records with string $parseString in a
total of $totFiles files, $noDuration with no duration.\n";
$allRecs = $totFiles = 0;
}

}

sub get_parse_routine {
my ( $type ) = @_;
return \&parse_ewp if ( $type == 1 );
return \&parse_pslogin if ( $type == 2 );
return \&parse_login if ( $type == 3 );
}

sub parse_ewp {
my $fileName = $File::Find::name;
return unless ($fileName =~ /^.*$logDate\.gz$/);

print "Ready to process -$fileName-\n";
print "test scope, parseString set in calling context
-$parseString-\n";

my $chkCount;

$totFiles++;
open (ZIPFILE, "gzip -dc $fileName |") || die "Can't open $fileName
$!\n";
while (<ZIPFILE>) {
next unless /\Q$parseString\E/i;
$chkCount++;
chomp;

my $part2 = (split /"/,$_)[2];
my $duration = (split / /,$part2)[3];

# print "part2 is -$part2- duration is -$duration-\n";

if ($duration =~ /^\d[\d\.]*$/) {
$stat->add_data($duration);
$recCount++;
}
else {
$noDuration++;
}
next;
if ($chkCount > 10) {
$chkCount = 0;
last;
}
}
close ZIPFILE;
}

sub parse_pslogin {
my $fileName = $File::Find::name;
return unless ($fileName =~ /^.*$logDate\.gz$/);

print "Ready to process -$fileName-\n";
print "test scope, parseString set in calling context
-$parseString-\n";

my $chkCount;

$totFiles++;
open ( ZIPFILE, "gzip -dc $fileName |" ) || die "Can't open
$fileName $!\n";
while ( <ZIPFILE> ) {
next unless /\Q$parseString\E/i;
$chkCount++;
chomp;

my $part6 = (split /"/,$_)[6];
my $duration = (split /\ /,$part6)[5];

# print "part6 is -$part6- duration is -$duration-\n";

if ( $duration =~ /^\d[\d\.]*$/ ) {
$stat->add_data($duration);
$recCount++;
}
else {
$noDuration++;
}
next;
if ($chkCount > 10) {
$chkCount = 0;
last;
}
my $part2 = (split /"/,$_)[2];
my $duration = (split / /,$part2)[3];

# print "part2 is -$part2- duration is -$duration-\n";

if ($duration =~ /^\d[\d\.]*$/) {
$stat->add_data($duration);
$recCount++;
}
else {
$noDuration++;
}
next;
if ($chkCount > 10) {
$chkCount = 0;
last;
}
}
close ZIPFILE;
}



sub parse_login {
my $fileName = $File::Find::name;
return unless ($fileName =~ /^.*$logDate\.gz$/);

print "Ready to process -$fileName-\n";
print "test scope, parseString set in calling context
-$parseString-\n";

my $chkCount;

$totFiles++;
open ( ZIPFILE, "gzip -dc $fileName |" ) || die "Can't open
$fileName $!\n";
while ( <ZIPFILE> ) {
next unless /\Q$parseString\E/i;
$chkCount++;
chomp;

my $duration = (split /\t/,$_)[13];

# print "duration is -$duration-\n";

if ( $duration =~ /^\d[\d\.]*$/ ) {
$stat->add_data($duration);
$recCount++;
}
else {
$noDuration++;
}
next;
if ($chkCount > 10) {
$chkCount = 0;
last;
}
}
close ZIPFILE;
}

.



Relevant Pages

  • Re: Zip a file programatically
    ... OK, Miyahn, your "unreliable" script works on WinXP SP2 if any ... > ZipFile = FS.BuildPath ... > On Error GoTo 0 ... > Sub SelectItem ...
    (microsoft.public.scripting.vbscript)
  • Re: Detecting is hyperthreading is enabled with WMI?
    ... It is too bad that WMI does not give this info. ... have to be done to the script. ... Public Sub DisplayProcessorInfo ... dim ProcessorSet, Processor ...
    (microsoft.public.windowsxp.wmi)
  • Cant make this page work
    ... I can't make this script work properly. ... The script at the bottom of the html page ... Does someone have a perl ... sub output_trace_headers { ...
    (comp.lang.javascript)
  • Re: Maybe I should try a different approach
    ... entire time my script is running, then have it close when my script is done and maybe have some dots keep adding to the text message until the script is fully completed? ... ' The "Three Ugly Hack" Script, ... Sub oATO_vbTimerEvent' timer event handler... ... Public Property Let Left ...
    (microsoft.public.scripting.vbscript)
  • Re: Win32_Product doesnt list all installed Applications
    ... 'Must have ADSI and WMI installed on PC running script. ... CONST ForReading = 1 ... Sub Connect ... strHTML = "Smoke'm if you Got'em" ...
    (microsoft.public.windows.server.scripting)