I've got an issue where I'm calling an external program (tetheral) to parse some QoS bits, but the problem is occasionally the IP i'm keying on doesn't respond, which causes the tethereal process to hang. since this check runs every few mins, if the remote host is down it can chew up resources on the box checking. I've gotten around this by programming the check with fork() and exec() so I can keep track of the pid of tethereal when it gets spawned, and kill it appropriately if it hasn't terminated in a given time frame.

so, that's all well and good, except the tethereal process I call has some rather complex arguments, so it spawns a shell to interpret them. My script can kill the tethereal process if it hangs, but now I have a duplicate shell running the tetheral process that doesn't get killed, and I can't keep track of. I've found on this site and others that you can avoid having exec() parse through a shell by giving the arguments as an array. the trouble is, I haven't yet figured out how to properly format these arguments into an array so that tethereal sees them correctly. this is what I need help with. here's the bit of code I'm calling now, that spawns the shell process (that I want to avoid):
exec("/usr/bin/tethereal -c 10 -i eth1 -f \"(! vlan 0) and src host $I +P and udp and port 5060\" -x | grep ^0010 > /var/tmp/tosbits.txt");

20070608 Janitored by Corion: Changed PRE to CODE tags


In reply to avoiding shell escapes with exec() by Anonymous Monk

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.