Hi,
I'm trying to write a script that will put a network interface down/up using ifconfig so that the mac address can be changed. The script will prompt the user to choose a interface, i.e (etc0,etc1,etc...) then, ask if the new mac address will be random, or one chosen by the user.

The problem is that I get an error when trying to execute ifconfig from the system function. Because the interface is selected from user input, I write the system function as system("ifconfig $device down");. If I remove down, there is no error. If I remove the variable $device and put eth0, there is no error. If I set the variable $device to eth0 above the system function, there is no error. Here is part of the script

### Test if a device has been selected #### if ($device eq "") { print "Please Choose a device\n"; system ("ifconfig"); print "Choice: "; $device = <>; } else { ### Display Change Mac Address Menu ### print "1. Create Random new Mac Address for device $device\n"; print "2. Create a Specefic New Mac Address for device $device\n"; print "3. Go Back to MAIN MENU\n\n"; print "Choice: "; $choice = <>; if ($choice == "1") { ### Create Random New MacAddress ### system("ifconfig $device down"); system("macchanger -r $device"); system("ifconfig $device up"); }

When the system function is executed it will do a ifconfig eth0 (if eth0 is what the user choose), then on a new line say: sh: line 1: down command not found.
Any ideas as to what could be causing this error? and how I can fix it?
Thanks in advance.


In reply to perl system function by ironside

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.