macOS Patching

Manu
New Contributor III

Hello,

I am currently attempting to write a script to patch a Mac computer.

This is my script:

#!/bin/bash

todayDate=$(date "+%d.%m.%Y")
patchingLogFile=patching_"$todayDate"

exec > /tmp/"$patchingLogFile".txt 2>&1
echo "Part 1:0 log file has been created"

computerMacOSVersionFirstValue=$( sw_vers -productVersion | /usr/bin/cut -d. -f1 )
macOSVersionUpdate="11.7.2"


if [ "$computerMacOSVersionFirstValue" == "11" ] ; then
	softwareupdate -R  --fetch-full-installer --full-installer-version 'macOS $macOSVersionUpdate' 2>&1
	else
	echo "Don't do the update"
fi
	

The problem I am getting, is that when I look in the log file, I get this return:

Scanning for macOS $macOSVersionUpdate installer

Install failed with error: Update not found

 But if I run the code:

softwareupdate -R  --fetch-full-installer --full-installer-version 'macOS 11.7.2' 2>&1

Then the computer will update with the intended version.
I don't know what I am doing wrong! Can a scripting guru help me please? That would be greatly appreciated.

Thank you

1 ACCEPTED SOLUTION

jamf-42
Valued Contributor II

and add after shebang

set -x 

while testing to debug and get output.. 

double quotes.. not single.. your not expanding the variable with single quotes hence the variable in the output 

View solution in original post

6 REPLIES 6

jamf-42
Valued Contributor II

and add after shebang

set -x 

while testing to debug and get output.. 

double quotes.. not single.. your not expanding the variable with single quotes hence the variable in the output 

Manu
New Contributor III

Wow!! The double quote did resolve my issue with the variable. Thank you!

But I don't understand what you mean when you wrote:


@jamf-42 wrote:

and add after shebang

set -x 

while testing to debug and get output.. 


I have updated my script with the double quote:

#!/bin/bash
todayDate=$(date "+%d.%m.%Y")
patchingLogFile=patching_"$todayDate"

exec > /tmp/"$patchingLogFile".txt 2>&1
echo "Part 1:0 log file has been created"

computerMacOSVersionFirstValue=$( sw_vers -productVersion | /usr/bin/cut -d. -f1 )
macOSVersionUpdate="11.7.2"


if [ "$computerMacOSVersionFirstValue" == "11" ] ; then
softwareupdate -R --fetch-full-installer --full-installer-version "macOS $macOSVersionUpdate" 2>&1
else
echo "Don't do the update"
fi

And the result on the text file is:

Scanning for macOS 11.7.2 installer

Install failed with error: Update not found

I am going to understand why the update didn't work, nevertheless, a very big step forward, so thank you very much for your help!! ✌️

mm2270
Legendary Contributor III

I don't think using "macOS <version>" is the correct syntax. I've never done it that way. I've always just used the version only and not included the "macOS" part when using the --fetch-full-installer flag.

I would run

sudo softwareupdate --list-full-installers

to see what it returns for full versions and only pick the numerical value after "Version: "

Manu
New Contributor III

Thank you for your response and your help.

I have tried the fllowing command changing it slightly, and th result was always the same:

For

 

softwareupdate -R --fetch-full-installer --full-installer-version "macOS $macOSVersionUpdate" 2>&1

 

I got:
Scanning for macOS 11.7.2 installer

For:

 

softwareupdate -R --fetch-full-installer --full-installer-version "macOS Big Sur $macOSVersionUpdate" 2>&1

 

I got:
Scanning for macOS Big Sur 11.7.2 installer

and for:

 

softwareupdate -R --fetch-full-installer --full-installer-version "$macOSVersionUpdate" 2>&1

 

I got:
Scanning for 11.7.2 installer

And for all 3 attempts, I got the following return message:

Install failed with error: Update not found

Which is odd because when you run:

sudo softwareupdate --list-full-installers

You get:

Finding available software
Software Update found the following full installers:
* Title: macOS Monterey, Version: 12.6.3, Size: 12406118533K
* Title: macOS Monterey, Version: 12.6.2, Size: 12395078361K
* Title: macOS Monterey, Version: 12.6.1, Size: 12399095056K
* Title: macOS Big Sur, Version: 11.7.3, Size: 12410109599K
* Title: macOS Big Sur, Version: 11.7.2, Size: 12410170728K
* Title: macOS Big Sur, Version: 11.7.1, Size: 12410109410K
* Title: macOS Big Sur, Version: 11.6.6, Size: 12412173576K
* Title: macOS Big Sur, Version: 11.6.5, Size: 12412317772K
* Title: macOS Big Sur, Version: 11.6.4, Size: 12439328867K
* Title: macOS Big Sur, Version: 11.6.3, Size: 12435122667K
* Title: macOS Big Sur, Version: 11.6.2, Size: 12433351292K
* Title: macOS Big Sur, Version: 11.6.1, Size: 12428472512K
* Title: macOS Big Sur, Version: 11.5.2, Size: 12440916552K
* Title: macOS Catalina, Version: 10.15.7, Size: 8248985973K
* Title: macOS Catalina, Version: 10.15.7, Size: 8248854894K
* Title: macOS Catalina, Version: 10.15.6, Size: 8248781171K
* Title: macOS Mojave, Version: 10.14.6, Size: 6038419486K
* Title: macOS High Sierra, Version: 10.13.6, Size: 5221689433K

 

 

 

jamf-42
Valued Contributor II

see here https://stackoverflow.com/questions/36273665/what-does-set-x-do 

when scripting it can be handy to add this at the start of your script.. it outputs the process of the script.. so you can see what's going on.. once your happy with it working.. you can remove it..

Manu
New Contributor III

Nice!! Thank you for your help, I have already learned a lot more!! 😁