Hello all, first post here as I learn to use Perl more efficiently! I have a script that pings a given host, and places the results in a log file. After this is done, I want to run another command in the same script taking that log file and cutting out a part using grep & cut and putting the results in a 2nd log file.
my @days = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday +); my @shortdays = qw( Sun Mon Tue Wed Thu Fri Sat ); my @months = qw(January February March April May June July August Sept +ember October November December); my @shortmonths = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) +; my ( $sec, $min, $hr, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time); my $longyr = $year + 1900; my $fixmo = $mon + 1; $LOGFILE = ">/home/***/public_html/packet/logs/$TARGET_HOST.$mday-$ +shortmonths[$mon]-$longyr.log"; open(LOGFILE) || die "Log file will not open.\n"; print LOGFILE "--------- $mday $shortmonths[$mon], $longyr, $hr:$mi +n:$sec ---------\n\n"; print "Content-type: text/html\n\n"; print "<HTML><PRE>\n"; print "<B>Please wait for script to run, or time out</B>\n"; open (IX,"$commands{$PROGRAM} $TARGET_HOST |"); while (<IX>) { chop $_; print "$_\n"; print LOGFILE "$_\n"; } print <<__END_OF_FOOTER__; </PRE> </HTML> __END_OF_FOOTER__ close (IX); $PACKET = ">/home/***/public_html/packet/logs/$TARGET_HOST.PL.$mday +-$shortmonths[$mon]-$longyr.log"; open(PACKET) || die "Packet loss file will not open.\n"; open (PL,"grep 'packet loss' /home/***/public_html/packet/logs/$TAR +GET_HOST.$mday-$shortmonths[$mon]-$longyr.log | cut -d ' ' -f 6 | cut + -d '%' -f1 > /home/***/public_html/packet/logs/$TARGET_HOST.PL.log") +; close (PL);
From a shell, I can easily execute the 2nd command (PL) and it will return the percentage of packet loss in the new log file ($TARGET_HOST.PL.log). However, when I run the script, the new log file is created, however there is nothing in it. Any help is appreciated!

Node content restored by GrandFather


In reply to File created but blank by diligent

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.