Posted on 05-19-2021 07:02 AM
Hi
looking for a command to get remote policies in JAMF which are older than 30 days.
Here is the script i got.
URL="https://jamfpro.talkingmoose.net:8443"
userName="API-Editor"
password="password"
currentDirectory=$( /usr/bin/dirname "$0" )
CURRENTSCRIPT=$( /usr/bin/basename -s .sh "$0" )
logFile="$currentDirectory/$CURRENTSCRIPT - $( /bin/date '+%y-%m-%d' ).log"
function logresult() {
if [ $? = 0 ] ; then
/bin/date "%Y-%m-%d %H:%M:%S $1" >> "$logFile"
else
/bin/date "%Y-%m-%d %H:%M:%S $2" >> "$logFile"
fi
}
startTime=$( /bin/date '+%s' )
logresult "--------------------- Begin Script ---------------------"
policyXML=$( /usr/bin/curl -k $URL/JSSResource/policies --user "$userName:$password" -H "Accept: text/xml" -X GET | /usr/bin/xmllint --format - )
logresult "Reading policy XML." "Failed to read policy XML."
idList=$( echo "$policyXML" | /usr/bin/egrep -B1 '<name>[0-9]+-[0-9]{2}-[0-9]{2} at [0-9]{1,2}:[0-9]{2,2} [AP]M | . | .</name>' | /usr/bin/grep '<id>' | /usr/bin/awk -F '[><]' '{print $3}' )
while IFS= read aLine
do
/usr/bin/curl -k "$URL/JSSResource/policies/id/$aLine" --user "$userName:$password" -X DELETE
logresult "Deleted ID "$aLine"." "Failed to delete ID "$aLine"."
idCount=$((idCount+1))
done <<< "$idList"
logresult "Completing script."
logresult "Processed $idCount policies."
stopTime=$( /bin/date '+%s' )
DIFF=$(($stopTime-$startTime))
logresult "Script operations took $DIFF seconds to complete."
logresult "---------------------- End Script ----------------------
"
exit 0