Solved

bash script/command to get the AD computer name

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

758 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

22 Experts available now in Live!

Get 1:1 Help Now