Home › Forums › OS X Server and Client Discussion › Questions and Answers › launchdaemons and dscl . -create
- This topic has 9 replies, 2 voices, and was last updated 14 years, 11 months ago by
Joy.
-
AuthorPosts
-
May 3, 2010 at 6:36 pm #378496
Joy
ParticipantI 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!
May 3, 2010 at 9:04 pm #378506Greg Neagle
ParticipantMore data needed.
Mind posting the launchd plist and maybe also the script?
-Greg
May 4, 2010 at 1:05 pm #378511Joy
ParticipantThanks for the reply. Below is the script I’m using and the launchdaemon:
Script
*******
!/bin/shmacAddress=`/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
May 4, 2010 at 5:34 pm #378515Greg Neagle
ParticipantLet’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
May 4, 2010 at 6:12 pm #378516Joy
ParticipantHi 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
May 4, 2010 at 6:23 pm #378517Joy
ParticipantSo 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.dtddict
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
plistMay 4, 2010 at 7:12 pm #378518Joy
Participantand 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:89May 5, 2010 at 4:05 pm #378527Joy
Participant[code]
[/code]
Label
com.attrsetup.sh
ProgramArguments
/Library/Scripts/Custom/attrsetup.sh
RunAtLoad
May 5, 2010 at 8:01 pm #378530Greg Neagle
ParticipantAnd you have this in /Library/LaunchDaemons/ ?
The permissions errors would imply that the script is running as a user other than root…
-Greg
May 6, 2010 at 1:56 pm #378537Joy
ParticipantI 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!!
-
AuthorPosts
- You must be logged in to reply to this topic.
Comments are closed