Posted on 05-16-2018 08:47 AM
I'm working upon a larger script to do some finder customisation and having a problem with a dscl lookup which is quite confusing unless I'm missing something silly!
All I'm wanting this small bit to do it echo out the path to the logged in active directory users network home directory, SMBHome.
Here's the really basic script
#!/bin/bash CurrentUser=$(stat -f%Su /dev/console | awk '!/root/') ADHome=$(dscl . -read /Users/"$CurrentUser" SMBHome) echo "$ADHome"
If I run that in terminal the result it outputs is different to what happens running the exact same commands manually. See the screen shot where I've run the script and then copied the contents directly into terminal and it gives a different answer.
As you can see in the script result it misses the first and then a from the path, I assuming I'm missing something but not sure what. Any one any ideas?
Posted on 05-16-2018 09:03 AM
That works just fine for me for both ways of executing it. I'm invoking the script via the same method as you as well.
Posted on 05-16-2018 09:20 AM
Thanks @CypherCookie
So I'm not necessary going mad, there is something weird going on, I'll give it a try on another mac later on.
Posted on 05-16-2018 09:21 AM
When executing the script, try doing it without "sh" Just use the path to the file.
Posted on 05-16-2018 09:24 AM
or
bash /path/to/file
Posted on 05-16-2018 09:44 AM
Doing it with the "sh" is removing the slash. Doing with just the path, gives the correct response. JAMF would run it without the "sh" since it's running as root.
Posted on 05-16-2018 10:50 AM
I've been messing with this for a while and I think your variable is fine, and it's just the combination of echo and bash that is chopping up your output.
If you want to check on the results, try something like this:
#!/bin/bash
CurrentUser=$(stat -f%Su /dev/console | awk '!/root/')
echo $CurrentUser
ADHome=$(dscl . -read /Users/"$CurrentUser" SMBHome)
justHome=$(dscl . -read /Users/"$CurrentUser" SMBHome | awk '{print $2}')
echo "ADHome Returns:"
echo ${ADHome}
echo "$ADHome"
echo $ADHome
printf '%s' $ADHome
printf '
'
echo "justHome Returns:"
echo ${justHome}
echo "$justHome"
echo $justHome
printf '%s' $justHome
printf '
'
Posted on 05-24-2018 12:58 PM
Have you tried updating your script to include the "/" between "$CurrentUser"/SMBHome?
ADHome=$(dscl . -read /Users/"$CurrentUser"/SMBHome)
Posted on 06-01-2018 03:40 AM
After a few weeks off just got back to looking at this, thanks for all the suggestions guys!
Thanks to @merps great test script it does look to work with the printf command rather than echo. The command which produces the right format is the one at the bottom:
printf '%s' $justHome
printf '
'
Now to combine it with the larger script for adding a users network home to their Finder sidebar.
Thanks again for all the help.