Home Forums OS X Server and Client Discussion Questions and Answers dscl scripts – revisited

  • This topic has 5 replies, 3 voices, and was last updated 14 years ago by Joy.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #378605
    Joy
    Participant

    I’m still having some issues with my script. I’ve simplified things in hopes of figuring out where it’s going wrong.

    The launchd works. The script works if I run it from command line with launchctl. My env is EXACTLY the same, both from command line and the launchd.

    If I remove the “ENetAddress $macAddress”, the computer group gets added, without any problem, either from the launchd or command line, just no Ethernet address.

    If I add the “ENetAddress $macAddress” it fails at the launchd, even though Console will show that it has read the record correctly and that it is there:

    Here are the players:

    Script:
    **********
    #!/bin/sh
    macAddress=`/sbin/ifconfig en0 | /usr/bin/grep ‘ether’ | /usr/bin/sed “s/^[[:space:]]ether //” | cut -f1 -d ” “`
    echo “$macAddress”
    /usr/bin/dscl . -create /Computers/Desktop ENetAddress $macAddress
    /usr/bin/dscl . -read /Computers/Desktop

    Launchd:
    *************
    [code]


    Label
    sh.attrsetup
    Program
    /Library/Scripts/Custom/attrsetup.sh
    RunAtLoad
    [/code]

    Console after the launchd has run:

    5/17/10 2:09:06 PM sh.attrsetup[51] 00:1f:5b:ea:90:89
    5/17/10 2:09:06 PM sh.attrsetup[51] AppleMetaNodeLocation: /Local/Default
    5/17/10 2:09:06 PM sh.attrsetup[51] ENetAddress: 00:1f:5b:ea:90:89
    5/17/10 2:09:06 PM sh.attrsetup[51] GeneratedUID: 5B5D58EA-6FCC-4E8A-A99E-673A7B734F52
    5/17/10 2:09:06 PM sh.attrsetup[51] RecordName: Desktop
    5/17/10 2:09:06 PM sh.attrsetup[51] RecordType: dsRecTypeStandard:Computers

    No errors are reported, but when I start up WGM, that Computer “Desktop” isn’t there and going to /var/db/dslocal/nodes/default/computers, shows it isn’t there either.

    #378611
    Greg Neagle
    Participant

    That would seem to imply that some other process is deleting the Desktop computer record _after_ your script creates it, since your script echos back the results of dscl . read /Computers/Desktop, proving that the record has been created.

    -Greg

    #378612
    Joy
    Participant

    One would think that, but the only launchd I have running is that one, other then the system ones. If I remove the ENetAddress part, the record gets added successfully. It is only when it tries to populate the ENetAddress key that the script fails.

    I posted the problem on the Apple forums and someone gave me a different way of getting the en0, by using a perl script and that works, using the exact same launchdaemon. Although it puts the MAC address in that field 4 times.

    I’ve opened an incident with Apple in hopes of shedding some light on the problem.

    #378618
    Greg Neagle
    Participant

    I can’t imagine why the method you are using to get the MAC layer address would matter, but here’s how I currently do it in my equivalent script:

    macAddress=`/sbin/ifconfig en0 | /usr/bin/awk ‘/ether/ {print $2}’`

    -Greg

    #380586
    berrty
    Participant

    I am sure a lot of people will be curious to know the answer to the issue you are having with the script!! It’s the first time I am coming across such a problem and was interested in the possible solutions and hope it works for you!! Hope you will keep updating on it!!

    #380608
    Joy
    Participant

    If I remember correctly, it was a combination of a couple of things. First, the dubious permissions on my launchagent and then the ole’ typos got me.

    Changed the launchagent to the right permissions, made sure my typing was correct and everything worked!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Comments are closed