Skip to main content
Question

Call a script after Configuration profile has ran

  • June 9, 2015
  • 3 replies
  • 29 views

Forum|alt.badge.img+3

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

Forum|alt.badge.img+14
  • Contributor
  • June 9, 2015

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.


Forum|alt.badge.img+16
  • Valued Contributor
  • June 9, 2015

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

Forum|alt.badge.img+16
  • Valued Contributor
  • June 9, 2015

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.