Terminal ComputerName Variable

I am trying to write a script that lets rsync write a copy of a folder to another mount vol.

rsync -av --delete /users/shared /Volumes/BackupMM/$HOST/

This isn't writing computername to back up dir. Ideas?

Message was edited by: Bill-C

Mac Book Pro 1G, Mac OS X (10.6.5)

Posted on Apr 1, 2011 5:06 AM

Reply
2 replies

Apr 1, 2011 7:56 AM in response to Bill-C

$HOSTNAME is a 'bash' specific feature. If you use a different shell for your script, then $HOSTNAME may not be available.

myHost=$(hostname -s)

will also get your hostname, and should work for all shells, as well as most Unix systems.

NOTE: $HOSTNAME and hostname -s will NOT always give you the name you set in your System Preferences -> Sharing -> Computer name. The above 2 names are obtained by asking your DNS server if they have a name for your nn.nn.nn.nn IP address. If the DNS server does not, then you get the Computer name you set. If they say yes, you could get anything.

This will get the value stored in System Preferences -> Sharing -> Computer name

myComputerName=$(networksetup -getcomputername)

By the way, Terminal, Unix, X11, and command line command, ssh, rsync, etc... questions are best asked in the Mac OS X Technologies > Unix Forum
<http://discussions.apple.com/forum.jspa?forumID=735>

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Terminal ComputerName Variable

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.