欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

自己亲自做的修改计算机的名称 有大用 有大大用

Change_ComputerName.sh  最好还要加上 NetBiosName 见  /node-admin/20053

修改计算机名称

#!/bin/bash    
#    

   
#管理员密码    
Passwd=$(/usr/bin/osascript -e 'display dialog "请输入管理员密码" with hidden answer default answer "" with icon note buttons {"Continue"} default button "Continue"    
    set result1 to result    
    set the text_data to text returned of the result    
    set the button_data to button returned of the result1    
    if button_data = "Cancel" then    
      return ""    
    end if    
    return text_data')  
if [ -z "$Passwd" ];then    
  exit 0;
fi    
   
if [ $Passwd = '123456789'  ]; then    

   
    #计算机名称    
    ComName=$(/usr/bin/osascript -e 'display dialog "请输入计算机名称" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"    
    set the date_data to text returned of the result    
    return date_data')    

   
    echo "计算机名称是 $ComName"  # echo "计算机名称是 $ComName"    
    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 "计算机名称修改成功!" buttons {"OK"}   default button "OK"')
    else    
       (/usr/bin/osascript -e  'display dialog "计算机名称修改失败!" buttons {"OK"}   default button "OK"')
    fi    

   
 else    
     (/usr/bin/osascript -e  'display dialog "密码不对!"')
     exit 0;
fi    





修改计算机名称2

#!/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`  #在jamf中whoami是root,不是当前用户
me=${HOME:7}
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


普通分类: