Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Help! String manipulation, Pipes, etc

Help! String manipulation, Pipes, etc
Thread Tools
Mac Enthusiast
Join Date: Mar 1999
Location: Portland, Oregon, United States
Status: Offline
Reply With Quote
Mar 29, 2005, 03:57 PM
 
I've been trying to figure out something that is probably very simple but it's taking much longer than I thought so I thought I'd ask here. I want to be able to set the hostname of many computers to match the "Computer Name" that the finder displays in the sharing Preference Pane. I need a command I can push out to a few hundred computers over the network using Remote Desktop.

The command to get the Computer name is

Code:
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -getcomputername
which produces the following output...

Code:
Computer Name: Laurence Hawkins
I then need to feed that output minus the "Computer Name: " into the "hostname" command to set the UNIX hostname to match. The problem is that I don't know how to remove the "Computer Name: " and replace the spaces in the name with underscores which seems to be necessary for this to function correctly.

If anyone has a simpler way to do this I would also appreciate any ideas! Really I just don't want to have to rename all these machines manually! The computer names are all correct, but for some reason many of the hostnames are hopelessly out of date and mention employee names that no longer work here!

Thanks!

edit: Fixed "code" tags. -[APi]TheMan
(Last edited by [APi]TheMan; Mar 29, 2005 at 04:23 PM. )
--Laurence
     
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Mar 29, 2005, 04:36 PM
 
This sounds good:
Code:
[thefro@nacho: ~]$ echo "Computer Name: Lots of Words With Spaces" | awk '{print substr($0,16)}' | sed "s/\ /_/g" Lots_of_Words_With_Spaces
Of course you'd be using `systemsetup -getcomputername` and piping it to `hostname`.

Anyone know a better way?
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
Mac Enthusiast
Join Date: Mar 1999
Location: Portland, Oregon, United States
Status: Offline
Reply With Quote
Mar 30, 2005, 10:42 AM
 
Thanks for the help... although after getting it working I discovered that Apple has already implemented a script that does exactly what I need...

Code:
/System/Library/SystemConfiguration/Kicker.bundle/Contents/Resources/set-hostname
Thanks!
--Laurence
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 05:00 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2