Solved

bash script/command to get the AD computer name

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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 …
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…
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 …

839 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