Solved

bash script/command to get the AD computer name

Posted on 2013-01-20
5
1,489 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

929 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now