Hello all. I am having difficulty with a spot of code. I have a feeling the answer is simple, and i am being stupid for missing it. In the code below I am running a call to ifconfig to change the mac address of the adapter to one in the given variable. I am trying to check for the error code "SIOCSIFHWADDR: Invalid Argument" When i run the backquoted command though, it does not capture the error code when it comes up. It always returns an empty set. I'd appreciate some help in understanding why this is and what I could do to get around it. I've included the relevant snippet of code below.
$code=`ifconfig eth0 hw ether $mac`; print "Returned error: $code \n"; if $code="SIOCSIFHWADDR: Invalid Argument"{&CMac;}
The conditional statement includes a recursive call to the function it is a part of. The idea is that it keeps attempting to change the MAC address until it hits a valid one. Unfortunately the $code variable always come up empty.


"One future, two choices. Oppose them or let them destroy us" - Propaghandi

In reply to Ifconfig error capture by WalkingZero

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.