Dear Perl Monks: I'm having an interesting problem with Perl on OS X Mountain Lion, perl v5.10.1. I replaced a bash script called on-firstboot.sh with a Perl script called on-firstboot.pl that does a number of things to a newly imaged Mac such as set the machine host name. I am using system to make these calls to bash, like so:
# Declare dependencies
... other code here ...
# Do system calls to set computer name
@args = ("scutil --set ComputerName '$name'");
@args = ("scutil --set HostName '$name'");
@args = ("scutil --set LocalHostName '$name'");
... script continues...
The first two of these work just fine. The $name variable contains a MAC address, in this case:
The third command above fails with this error:
SCPreferencesSetLocalHostName() failed: Invalid argument
It's almost as if the first two commands get the variable $name contents correctly and the third gets an empty string.
Any ideas? Perhaps I need to escape some of these quote characters? I used single quotes to avoid a quoting issue. The commands at the Terminal in OS X work fine with the MAC address in question whether I use single quotes or double-quotes. The failure only happens in the Perl script.
Other system calls in the Perl script are working fine. Perhaps I should insert some sort of sleep command to pause between system calls? (How does one sleep in Perl?)
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||