0

I want to launch tcpdump on linux shell as a background process using a perl script but I have to parse the output after which i need to kill the process. How can I do this ?

Dcoder
  • 379
  • 2
  • 7
  • 13

1 Answers1

1

I Unix, the traditional way is to write small and very specialized programs and pipe them together. Why don't you just pipe tcpdump output into your script stdin?

My perl is a little rusty:

$| = 1;
my $pid = open(DUMP, "tcpdump -i eth1 -l -n 2>\&1 |");

while(<DUMP>) {
    # do something
    if($some_condition) {
        `kill $pid`;
        last;
    }
}
Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153