Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

bash script/command to get the AD computer name

Posted on 2013-01-20
5
Medium Priority
?
1,570 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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 …

715 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