Posted on 10-27-2011 05:20 AM
* I have changed the subject to make it easy to find from archive*
Here is the script to change the name with ease in Casper Self Service (MCX applied to disabled Sharing prefs Naming). Thanks guys for all the help with osascript.
I have tested both scripts successfully in my environment. I suggest test it before using in your environment.
Posted on 10-25-2011 07:00 PM
hanges their Mac names)
#!/bin/sh
# This script will remove existing Directory records and will reset Search
Paths
# to /Active Directory/mycompany.com
# Tested with 10.6.x
# Remove all files containing AD bindings informations
#####################################
#Clock restart / Remove existing settings
#####################################
#Restart ntpdate
StartService ()
{
if [ "${TIMESYNC:-YES-}" "-YES-" ] &&
! GetPID ntpd > /dev/null; then
CheckForNetwork
if [ -f /var/run/NetworkTime.StartupItem -o "${NETWORKUP}" "-NO-" ]; th
en exit; fi
touch /var/run/NetworkTime.StartupItem
echo =93Starting network time synchronization=94
# Synchronize our clock to the network=92s time,
# then fire off ntpd to keep the clock in sync.
ntpdate -bvs
ntpd -f /var/run/ntp.drift -p /var/run/ntpd.pid
fi
}
# Remove exisiting
logger =93Removing existing DS Config=94
if [ ! -d "/Library/Preferences/DirectoryService/ActiveDirectory" ]; then
rm -R /Library/Preferences/DirectoryService/ActiveDirectory*
fi
if [ ! -d "/Library/Preferences/DirectoryService/DSLDAPv3PlugInConfig" ]; t
hen
rm -R /Library/Preferences/DirectoryService/DSLDAPv3PlugInConfig*
fi
if [ ! -d "/Library/Preferences/DirectoryService/SearchNode" ]; then
rm -R /Library/Preferences/DirectoryService/SearchNode*
fi
if [ ! -d "/Library/Preferences/DirectoryService/ContactsNode" ]; then
rm -R /Library/Preferences/DirectoryService/ContactsNode*
fi
if [ ! -d "/Library/Preferences/edu.mit.Kerberos" ]; then
rm -R /Library/Preferences/edu.mit.Kerberos
fi
# Restart DirectoryService (necessary to reload AD plugin activation settin
gs)
killall DirectoryService
/bin/sleep 3
exit 0
#!/bin/bash
# Lets enter the computername with GUI
getname()
{
asmsg`arch -i386 /usr/bin/osascript << EOT
tell app "System Events"
Activate
set foo to text returned of (display dialog "Enter the new name of the Comp
uter" buttons {"OK"} default answer "Type Computer Name Here")
end tell
EOT`
if [ "$asmsg" "false" ]; then
getname
else
echo $asmsg
fi
}
computernamegetname
# Set the computername
networksetup -setcomputername ${computername}
# This will update the original hostname record and it will keep the old re
cord with date stamp then set the permissions
mv /Library/Receipts/cname.txt /Library/Receipts/oldcname_`date +%M-%H-%m-%
d-%y`.txt
networksetup -getcomputername > /Library/Receipts/cname.txt
chmod -R 644 /Library/Receipts/cname.txt
chown -R root:wheel /Library/Receipts/cname.txt
# lets set the computer
setNamecat /Library/Receipts/cname.txt
scutil --set ComputerName ${setName}
scutil --set LocalHostName ${setName}
# Run Recon to update JSS record with the new name
jamf recon
exit 0 ## computermame and the record updated successfully
exit 1 ## fail
I hope this is useful=85
Cem