macOS dynamic rename from system_profiler details

79 Views Asked by At

I am looking to write a small script to dynamically rename macOS devices from system_profiler information but am new to bash and am not sure my approach is correct or best practice.

I have written a script (which I know doesn't work) but would like some guidance on how to approach this. My below script makes logical sense in my mind, but I know is incorrect:

#!/bin/bash          
        mod= system_profiler SPHardwareDataType | awk '/Model Identifier/ {print $3}'

        #Check if iMac or MacBook
        if [[ $mod = *"MacBook"* ]]; then 
              $mod | cut -c 1-3
        else 
              $mod | cut -c 1-4
        fi


        SN= system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' # Display the Serial Number


        echo $mod$SN

So in my mind what should happen is the Model Identifier should check if it is a Macbook, and return "MacB" if so, else check if iMac and return "iMac".

The final echo would be along the lines of iMacXXXXXXXXX.

0

There are 0 best solutions below