Set Terminal disc access in Jamf

Franky779
New Contributor III

Hi,

Jamf is supporting default scripts for checking time machine backups. But with new versions of mac os this won´t work beuacse diskutil is using PlistBuddy. This has no disc access. If i enable Terminal in full disk access those scripts are working again.

 

Without disc access

Franky779_0-1710861136165.png

 

With disc access

Franky779_1-1710861171604.png

 

Franky779_2-1710861203783.png

 

 

How can i set Terminal do full disc access via configuration profile?

 

Greets Frank

4 REPLIES 4

jamf-42
Valued Contributor II

you don't want to grant terminal full disk access.. thats 'a bad idea' 

not sure why plistbuddy is requiring access, but this does not.. you'll need to work that a bit to get the result you need, but you get the idea.

defaults read /Library/Preferences/com.apple.TimeMachine.plist | grep LastDestinationID

Franky779
New Contributor III

This is the script that Jamf offers in Custom attributes. This does not work anymore with newer MacOS Version. 

#!/bin/sh

enabled=`/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine AutoBackup`

if [ "$enabled" == "1" ]; then

    # Determine the OS version since the destination key name differs on OS

    OS=`/usr/bin/sw_vers -productVersion | /usr/bin/colrm 5`

    
    if [[ "$OS" < "10.7" ]]; then

        backupDestination=`/usr/sbin/diskutil info $(/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine "DestinationVolumeUUID") | grep "Mount Point" | /usr/bin/cut -c 30-`

        validateDestination=`/usr/sbin/diskutil info $(/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine "DestinationVolumeUUID") | awk '{print $1, $2}'`

    elif [ "$OS" == "10.7" ]; then

        backupDestination=`/usr/sbin/diskutil info $(/usr/libexec/PlistBuddy -c "Print DestinationVolumeUUIDs:0" /Library/Preferences/com.apple.TimeMachine.plist) | grep "Mount Point" | /usr/bin/cut -c 30-`

        validateDestination=`/usr/sbin/diskutil info $(/usr/libexec/PlistBuddy -c "Print DestinationVolumeUUIDs:0" /Library/Preferences/com.apple.TimeMachine.plist) | awk '{print $1, $2}'`

    elif [[ "$OS" > "10.7" ]]; then

        backupDestination=`/usr/sbin/diskutil info $(/usr/libexec/PlistBuddy -c "Print Destinations:0:DestinationUUIDs:0" /Library/Preferences/com.apple.TimeMachine.plist) | grep "Mount Point" | /usr/bin/cut -c 30-`

        validateDestination=`/usr/sbin/diskutil info $(/usr/libexec/PlistBuddy -c "Print Destinations:0:DestinationUUIDs:0" /Library/Preferences/com.apple.TimeMachine.plist) | awk '{print $1, $2}'`

    fi

​

    if [ "$validateDestination" == "Could not" ];then

        echo "<result>Destination not mounted</result>"

    else

        echo "<result>$backupDestination</result>"

    fi

else

    echo "<result>Not enabled.</result>"

fi

 

I will try your snipped. Thanks

Franky779
New Contributor III

OK, i changed the scripts and i want to share them if somebody else wants to check time machine status

 

Last succesfull backup

#!/bin/bash

# Plist-Datei, die das Time Machine Setup enthält
TM_PLIST="/Library/Preferences/com.apple.TimeMachine.plist"

# Überprüfe, ob die Plist-Datei existiert
if [ ! -f "$TM_PLIST" ]; then
  echo "Die Datei $TM_PLIST existiert nicht."
  exit 1
fi

# Verwende defaults read und perl, um das Datum des letzten Backups zu finden
last_backup_date=$(defaults read "$TM_PLIST" Destinations | \
  perl -0777 -ne 'print "$1\n" if /SnapshotDates\s+=\s+\(\s+(.*?)\s+\)/s')

# Extrahiere das letzte Datum (das letzte Backup)
last_successful_backup_date=$(echo "$last_backup_date" | tail -n 1 | tr -d '[:space:]' | sed 's/"//g')

# Überprüfe, ob ein Datum vorhanden ist
if [ -n "$last_successful_backup_date" ]; then
  # Schneide die letzten 5 Stellen ab
  last_successful_backup_date=$(echo "$last_successful_backup_date" | cut -c 1-$((${#last_successful_backup_date}-5)))
  
  # Ausgabe des letzten erfolgreichen Backup-Datums
  echo "<result>$last_successful_backup_date</result>"
else
  echo "<result>1907.01.01 01.00.00</result>"
fi

 

 

Get backup destination

#!/bin/bash

# Plist-Datei, die das Time Machine Setup enthält
TM_PLIST="/Library/Preferences/com.apple.TimeMachine.plist"

# Überprüfe, ob die Plist-Datei existiert
if [ ! -f "$TM_PLIST" ]; then
  echo "Die Datei $TM_PLIST existiert nicht."
  exit 1
fi

# Verwende PlistBuddy, um das letzte Time Machine Backup-Ziel zu erhalten
last_backup_target=$(/usr/libexec/PlistBuddy -c "Print Destinations:0:LastKnownVolumeName" "$TM_PLIST")



# Ausgabe des letzten Backup-Ziels
if [ -z "${VAR}" ]; then
    echo "<result>$last_backup_target</result>"
else
    echo "<result>Unknown</result>"
fi

 

 

Franky779
New Contributor III

Sorry there was an error in return last backup date.

#!/bin/bash

# Plist-Datei, die das Time Machine Setup enthält
TM_PLIST="/Library/Preferences/com.apple.TimeMachine.plist"

# Überprüfe, ob die Plist-Datei existiert
if [ ! -f "$TM_PLIST" ]; then
  echo "Die Datei $TM_PLIST existiert nicht."
  exit 1
fi

# Verwende defaults read und perl, um das Datum des letzten Backups zu finden
last_backup_date=$(defaults read "$TM_PLIST" Destinations | \
  perl -0777 -ne 'print "$1\n" if /SnapshotDates\s+=\s+\(\s+(.*?)\s+\)/s')

# Extrahiere das letzte Datum (das letzte Backup)
last_successful_backup_date=$(echo "$last_backup_date" | tail -n 1 | tr -d '[:space:]' | sed 's/"//g')

# Überprüfe, ob ein Datum vorhanden ist
if [ -n "$last_successful_backup_date" ]; then
  # Extrahiere das Jahr, den Monat, den Tag, die Stunde, die Minute und die Sekunde
  year=$(echo "$last_successful_backup_date" | cut -c 1-4)
  month=$(echo "$last_successful_backup_date" | cut -c 6-7)
  day=$(echo "$last_successful_backup_date" | cut -c 9-10)
  hour=$(echo "$last_successful_backup_date" | cut -c 11-12)
  minute=$(echo "$last_successful_backup_date" | cut -c 14-15)
  second=$(echo "$last_successful_backup_date" | cut -c 17-18)

  # Formatieren des Datums im "YYYY.MM.DD hh:mm:ss" Format
  formatted_date="${year}.${month}.${day} ${hour}:${minute}:${second}"

  # Ausgabe des letzten erfolgreichen Backup-Datums
  echo "<result>$formatted_date</result>"
else
  echo "<result>1907.01.01 01.00.00</result>"
fi