#!/bin/bash
#
random_num1=$(( (RANDOM % 26) + 65 ))
random_char1=$(printf "\\$(printf '%03o' $random_num1)")
random_num2=$(( (RANDOM % 26) + 65 ))
random_char2=$(printf "\\$(printf '%03o' $random_num2)")
#echo "${random_char1}${random_char2}"
me=`whoami`
ME=`echo "${me}" | tr '[:lower:]' '[:upper:]'` #转成大写
if [[ $ME == "JS-*" ]];then
me=${me:3}
fi
ComName="JS-${me}${random_char1}${random_char2}"
#echo $computerName
sudo scutil --set ComputerName $ComName
sudo scutil --set HostName $ComName
sudo scutil --set LocalHostName $ComName
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $ComName
sudo jamf recon
if [ $? = 0 ]; then
(/usr/bin/osascript -e 'display dialog "计算机名称修改成功,计算机名称为 ${ComName} !" buttons {"OK"} default button "OK"')
else
(/usr/bin/osascript -e 'display dialog "计算机名称修改失败!" buttons {"OK"} default button "OK"')
fi