You seem to count all files in /tmp that have the string 'files' in the name and if you find 3 or more you try to kill tcpdump

I'm guessing here that you wanted to search for 'file' because that's in the name of the logfiles and the 3 should have been a 10. That would work, but other programs might produce a file with 'file' included in the name. For example previous incarnations of your script

To be sure to count only logfiles of tcpdump, you could generate a (large) random number (random so that old tcpdump-logs don't count when you restart the program), put that into the name and search for that.

Also the sleep should be inside the while loop, otherwise your program will use 100% CPU.

#!/bin/perl -w srand(time()^$$); my $number= int(rand(100000000)); system "tcpdump -i bge1 -s0 -w /tmp/file$number.out -C 1 &"; while(true){ sleep 2; @array1 = `ls -1 /tmp | grep $number`; $result=@array1; if ($result > 9){
I also changed ls-l to ls -1 which lists one file per line too, but without the chance that the length of a file is equal to the random number.

I only scimmed over the rest of your code but couldn't find any obvious mistakes there.

EDIT: pc88mxer found another bug, so I corrected that (the missing '&') in the code.


In reply to Re: kill process when files created... by jethro
in thread kill process when files created... by onlineperluser

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.