Posted on 04-07-2017 02:07 PM
Hello folks, thanks in advance. I am trying clean up my environment, do any of you know an efficient way flush cached packages in a jamf managed device? Is the jamf command in terminal?
Thank you so much.
Posted on 04-07-2017 02:15 PM
Here's your answer:
https://www.jamf.com/jamf-nation/discussions/5878/removing-or-purging-the-waiting-room#responseChild101042
Posted on 04-09-2017 09:33 AM
Here's the script that I use. While the script linked to by @rqomsiya will clear the entire Waiting Room folder, my script will only delete those packages that match a base name passed to the script in the $4 argument. For instance, if you pass "Microsoft-Office2016-Excel" in $4, it would delete packages "Microsoft-Office2016-Excel-15.31.pkg", "Microsoft-Office2016-Excel-15.30.pkg", and so on. While the script currently only handles one package, eventually I plan on adding the ability to remove multiple packages. Just hasn't been a huge priority; this handles 90% of our need as-is.
Part of the reason for approaching the purge of older Waiting Room packages this way is that we have multiple policies caching packages at different times, and separate polices that install the cached package at a different time. Those policies might not all execute at the same time. If we were to remove all packages from the Waiting Room at once, we'd break some policies that expect to install a cached package.
#!/bin/bash
# declare variables and helpers
LogIt="/usr/bin/logger -t purgeWaitingRoom.bash "
STATUSCODE=0
# check for argument in first available argument slot under the JSS.
# Right now only operating with the assumption that there will only be one argument passed
if [ ! -z $4 ]
then
pkgBaseName="$4"
$LogIt Request to delete cached package $pkgBaseName
echo "Packages to be deleted: $pkgBaseName"
else
echo "No package name provided. Exiting with failure."
$LogIt No package base name provided. Exiting.
exit 1
fi
# find the cached packages in the Waiting Room, and use a while loop (hopefully white-space safe) to delete the package
echo "Finding previously-cached packages named $pkgBaseName"
find /Library/Application Support/JAMF/Waiting Room -name "$pkgBaseName*" -print0 | while read -d $'' pkg
do
echo -n "Found $pkg ..."
$LogIt Attempting to delete $pkg
find /Library/Application Support/JAMF/Waiting Room -name $(basename "$pkg") -delete
[[ $? = 0 ]] && echo " Package deleted"; $LogIt SUCCESS - $pkg deleted || echo -e "
###FAILED to delete package $pkg"; STATUSCODE=2
done
if [ $STATUSCODE != 0 ]
then
echo "Unable to delete old package - code $STATUSCODE"
$LogIt Unable to delete packages starting with name $pkgToDelete, error $STATUSCODE
else
echo "Package purge successful"
fi
exit $STATUSCODE
Posted on 04-10-2017 11:53 AM
Thank you both! I really appreciate it. It was what I was looking for.
Posted on 11-01-2018 08:35 AM
Hi @mikeh I am hoping you can advice me on this as my bash scripting is not great. Your script works great if the package name does not have any spaces between the name. The cached package I want to delete does have spaces between the names and the script fails with the following
Found /Library/Application Support/JAMF/Waiting Room/Install macOS Mojave v10.4.pkg ...find: macOS: unknown primary or operator
Found /Library/Application Support/JAMF/Waiting Room/Install macOS Mojave v10.4.pkg.cache.xml ...find: macOS: unknown primary or operator
what do I need to modify in the script to make this work with package names with spaces?
Thanks