Call a script after Configuration profile has ran

DoAFlip
New Contributor

Is there a way to call a script after a configuration profile has ran? I need to delete an old mobileconfig that was installed before JSS was installed, but only after the new profile is in place.

Thanks.

3 REPLIES 3

rlandgraf
Contributor

You could create an extension attribute to see if the config is installed, then create a smart group from that and remove the old one. It may not be instantaneous, but it is an option.

Look
Valued Contributor III

Another option is to just have a script that runs periodically and queries the profiles and deletes the old if the new one exists.
I wrote a script to find old WiFi profiles, might be helpful for ides. I changes WIFI_PROFILE_NAME in the awk statement form pur organisation specfic name.

#!/bin/bash

#Global Variable
STALE_DATE="2015-01-19"
STALE_DATE=$(echo $STALE_DATE | sed 's/[^0-9]*//g')
WIFI_PROFILES=$(Profiles -Lv | awk '/attribute: name:/ && / WIFI_PROFILE_NAME/,/attribute: profileIdentifier:/' | awk '/attribute: profileIdentifier:/ {print $4}')
for WIFI_PROFILE in $WIFI_PROFILES
do
echo Profile: $WIFI_PROFILE
WIFI_DATE=$(Profiles -Lv | sort -r | awk '/attribute: profileIdentifier: '$WIFI_PROFILE'/,/attribute: installationDate:/' | awk '/attribute: installationDate:/ {print $4}')
echo Install: $WIFI_DATE
WIFI_DATE=$(echo $WIFI_DATE | sed 's/[^0-9]*//g')
if [ $WIFI_DATE -lt $STALE_DATE ]
then
echo The profile "$WIFI_PROFILE" is STALE
echo Attempting to remove stale profile
profiles -R -p "$WIFI_PROFILE"
else
echo The profile "$WIFI_PROFILE" is CURRENT
fi
done
exit 0

Look
Valued Contributor III

Just a code sample not a solution to your actual problem of course :) but a launchAgent/Daemon that looked for both profiles, deleted the one you wanted then disabled itself might work.