Script to check OS version and to install necessary updates for Safari

Rosen
New Contributor

Hello, Jamf community. I am trying to create a script which I can deploy via Jamf to a number of clients. The script should check the OS version and push the installation of Security Update for Safari 13.1.1. Unfortunately it returns a error " text.txt: line 15: syntax error: unexpected end of file" and i am not able to understand why is this happening.
Here is the script:

!/bin/bash

sw_vers

if [[ "$ProductVersion" == "10.13.6" ]]; then
softwareupdate -i 'Safari13.1.1HighSierraAuto-13.1.1'
elif [[ "$ProductVersion" == "10.14.6" ]]; then softwareupdate -i 'Safari13.1.1MojaveAuto-13.1.1'

sleep 1

exit 0

4 REPLIES 4

Chris_Hafner
Valued Contributor II

I am not the expert here... but don't you need another else statement to cover all other conditions?

bmee
Contributor

we used softwareupdate to check and install patches on all of our devices.

Mauricio
Contributor III

Why not use smart groups to scope the macOS versions you want to target and apply that to the policy?

ukarulis
New Contributor II

Add "fi" after "elif" and "#" before anything on first line. Should work then.

#!/bin/bash
sw_vers

if [[ "$ProductVersion" == "10.13.6" ]]; then
softwareupdate -i 'Safari13.1.1HighSierraAuto-13.1.1'
elif [[ "$ProductVersion" == "10.14.6" ]]; then softwareupdate -i 'Safari13.1.1MojaveAuto-13.1.1'
fi
sleep 1

exit 0

Also can't find any variable defined, so I guess this script below is something you're looking for -

#!/bin/bash
ProductVersion=$(sw_vers | grep "ProductVersion" | awk '{ print $2; }')
​
if [[ "$ProductVersion" == "10.13.6" ]]; then
softwareupdate -i 'Safari13.1.1HighSierraAuto-13.1.1'
elif [[ "$ProductVersion" == "10.14.6" ]]; then softwareupdate -i 'Safari13.1.1MojaveAuto-13.1.1'
fi
sleep 1
​
exit 0

Also it would be good to add "else" to get some output as well if none of defined OS versions doesn't match in if statement, e.g. -

#!/bin/bash
ProductVersion=$(sw_vers | grep "ProductVersion" | awk '{ print $2; }')
​
if [[ "$ProductVersion" == "10.13.6" ]]; then
softwareupdate -i 'Safari13.1.1HighSierraAuto-13.1.1'
elif [[ "$ProductVersion" == "10.14.6" ]]; then softwareupdate -i 'Safari13.1.1MojaveAuto-13.1.1'
else
echo "OS version didn't match"
fi
sleep 1
​
exit 0