Solved

bash script/command to get the AD computer name

Posted on 2013-01-20
5
1,522 Views
Last Modified: 2013-01-28
hi there,

I need to find out a way of how to get the AD bound computer name of a computer via bash script.

Reason being that ive recently deployStudio deployed an image to a few hundred clients only to realise that the bind-name is not reflected into the LocalHostName, HostName or ComputerName values in OSX. What id like to do is deploy a script/command via ARD  that will grab the AD compName then:

scutil --set ComputerName $ADCompName
scutil --set LocalHostName $ADCompName
scutil --set HostName $ADCompName

Thanks for all assistance experts.
0
Comment
Question by:CNCS_AUS
5 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 38804250
I'm not sure, I understand the question, so sorry, if I'm wrong.

sudo scutil --set ComputerName newName
sudo scutil --set HostName newName
sudo scutil --set LocalHostName newName
Do you ask about that?

Mac OS X 10.6 Server Admin: Changing the Server’s Computer Name and the Local Hostname

http://osxdaily.com/2010/09/06/change-your-mac-hostname-via-terminal/

The following line will show the computer name in bash:
networksetup -getcomputername

This one will show the hostname:
sysctl -n kern.hostname

Please take a look here:
Script to bind to Active Directory (10.7)
0
 

Author Comment

by:CNCS_AUS
ID: 38804473
Hi there --

I want to do the exsact opposite as to what you've described friend. I want to somehow grab the AD computername, that is, the computername that was used to bind to AD and THEN set the variables/values of ComputerName, LocalHostName, HostName to the value of the computer name.

Any ideas?

Thanks alot
0
 
LVL 40

Expert Comment

by:noci
ID: 38805402
Is samba involved?
if so look for "netbios name" in the smb.conf.

Otherwise check the configuration of the tool you connect to AD with.
0
 
LVL 10

Accepted Solution

by:
schaps earned 500 total points
ID: 38824857
I am not a scripting expert, but I came up with a script you can send with ARD to accomplish the task. It seems there is a change from 10.6 and earlier to 10.7-10.8, which is that a dollar sign is appended to the end of the Computer name record in 10.7 and 10.8. Whether that bothers you or not, the "set --LocalHostName" fails when there is a dollar sign at the end. I came up with two slightly different scripts, one which removes the last character of the name, and one which does not. I am sure there is a way to merge this into one script which removes the dollar sign if it is present, but these two scripts work:

For 10.5 and 10.6:
#!/bin/sh
ADCompNametemp=`dsconfigad -show | grep "Computer Account" | sed 's/Computer Account//' | sed 's/=//'`
ADCompName=${ADCompNametemp//[[:space:]]/}
scutil --set HostName "$ADCompName"
scutil --set LocalHostName "$ADCompName"
scutil --set ComputerName "$ADCompName"

Open in new window


For 10.7-10.8
#!/bin/sh
ADCompNametemp=`dsconfigad -show | grep "Computer Account" | sed 's/Computer Account//' | sed 's/=//'`
ADCompNametemp2=${ADCompNametemp//[[:space:]]/}
ADCompName=${ADCompNametemp2%?}
scutil --set HostName "$ADCompName"
scutil --set LocalHostName "$ADCompName"
scutil --set ComputerName "$ADCompName"

Open in new window

0
 

Author Closing Comment

by:CNCS_AUS
ID: 38826242
Great Solution friend. Thank you very much!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question