Home Forums OS X Server and Client Discussion Questions and Answers launchdaemons and dscl . -create

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #378496
    Joy
    Participant

    I have a script that determines if the machines is a laptop or a desktop, and the creates a local group and populates the enetaddress with the correct information. It works when I run from the command line, but fails if I set it up as a launchdaemon.

    I have tried putting the plist in both the launchdaemons and launchagents folders, yet it errors out everytime, but I can get into terminal and manually run it with success.

    Does anyone have any other idea I can try?

    Thanks in advance!

    #378506
    Greg Neagle
    Participant

    More data needed.

    Mind posting the launchd plist and maybe also the script?

    -Greg

    #378511
    Joy
    Participant

    Thanks for the reply. Below is the script I’m using and the launchdaemon:

    Script
    *******
    !/bin/sh

    macAddress=`/sbin/ifconfig en0 | /usr/bin/grep ‘ether’ | /usr/bin/sed “s/^[[:space:]]ether //” | cut -f1 -d ” “`

    echo $macAddress

    MACHINE_TYPE=`/usr/sbin/system_profiler SPHardwareDataType | grep “Model Identifier” | grep “Book”`

    if [ “$MACHINE_TYPE” = “Book” ]; then
    computerRecordName=Laptop
    else
    computerRecordName=Desktop
    fi

    /usr/bin/dscl . -create /computers/$computerRecordName ENetAddress $macAddress

    echo “was: $storedMacAddress”
    echo “now: $macAddress”

    Launchdaemon
    ****


    Label
    com.attrsetup.sh
    ProgramArguments

    /Library/Scripts/Custom/attrsetup.sh

    RunAtLoad

    #378515
    Greg Neagle
    Participant

    Let’s see.

    The first line of the script has an illegal line (maybe the forum software munged it?). It should be

    [code]#!/bin/sh[/code]

    Is the script marked as executable?

    The forum software munged the launchd plist, so it’s hard to guess what else might be at issue.
    When you say you can run it from the command line, how do you invoke it?

    -Greg

    #378516
    Joy
    Participant

    Hi Greg,

    First, big THANKS for all your articles. I refer to them a LOT!

    Next, yes, I do have the #!/bin/sh as my first line. I failed to grab all the text in my copy/paste.

    Third, yes, the forum did mess up my plist. I’m trying it again. When I drop to the command line, I type in sudo ./attrsetup.sh and it runs perfectly, every time. To make it an executable, I typed the following chmod a+x path/to/script. Is this correct?



    Label
    com.attrsetup.sh
    ProgramArguments

    /Library/Scripts/Custom/attrsetup.sh

    RunAtLoad

    Joy

    #378517
    Joy
    Participant

    So much for that try on the plist.

    xml version=”1.0″ encoding=”UTF-8″
    DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd dict
    key ,Label key
    string com.attrsetup.sh string
    key ProgramArguments key
    array
    string /Library/Scripts/Custom/attrsetup.sh string
    array
    key RunAtLoad key
    true
    dict
    plist

    #378518
    Joy
    Participant

    and if it is of any help, here is what Console has to say about everything:

    5/4/10 2:57:51 PM com.attrsetup.plist[112] 00:1f:5b:ea:90:89
    5/4/10 2:57:52 PM com.attrsetup.plist[112]

    attribute status: eDSPermissionError
    5/4/10 2:57:52 PM com.attrsetup.plist[112] DS Error: -14120 (eDSPermissionError)
    5/4/10 2:57:52 PM com.attrsetup.plist[112] was:
    5/4/10 2:57:52 PM com.attrsetup.plist[112] now: 00:1f:5b:ea:90:89

    #378527
    Joy
    Participant

    [code]


    Label
    com.attrsetup.sh
    ProgramArguments

    /Library/Scripts/Custom/attrsetup.sh

    RunAtLoad
    [/code]

    #378530
    Greg Neagle
    Participant

    And you have this in /Library/LaunchDaemons/ ?

    The permissions errors would imply that the script is running as a user other than root…

    -Greg

    #378537
    Joy
    Participant

    I found the issue. It was a permissions error, but I also had to delay the launchd, because the ethernet wasn’t going active before the script ran so the macaddress was always nothing.

    Thanks for the direction!!

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

Comments are closed