Policys Triggers

PabloIbero
New Contributor

Hi,

Does anyone know how to set up a policy thta triggers every 2 montths (or a specific time)?

I want to set up a policy that tiggers a script that moves all of the files of the download folder to the trash (i already have the script), that is cus the computers are used by students that donwlaond multiple files for their projects, but rather that delete those files at the end of semestres y prefer to set up a policy that triggres the scrpit once every two months.

Is it possible?

 

Thanks in advance.

4 REPLIES 4

stevewood
Honored Contributor II
Honored Contributor II

Not natively in Jamf Pro. You can set a policy to run Once per Month, but not once every other month. 

A solution would be to utilize a LaunchDaemon that ran on the schedule you want that simply used the Jamf binary to call a specific policy. The policy could be set to use a Custom trigger and set to Ongoing frequency. The LaunchDaemon would call the policy using that custom trigger.

mdp
Contributor

Another option if you don't want to run a cron job or launch daemon:

  • At the end of your script for your policy, add a line that saves today's date to a hidden file on the computer
  • Create an extension attribute (data type "date") that reads that file and imports the date
  • Create a smart group with that extension attribute and "more than [60] days ago"
  • Make that smart group the scope of the policy and set the frequency to daily

That's assuming you wanted every computer to get this policy; otherwise, you change your smart group to "AND [whatever your other criteria is]". You could also do something similar without saving a hidden file with a call to the API when your script finishes, but you'd have to put credentials in the script, which isn't ideal.

---
Matthew Prins -- Jamf Scripts @ Github

Tangentism
Contributor III

Another way to do it (as these are all going to be slightly cludgy fixes) would be to clone the policy 5 times and set the scheduled dates at the set times throughout the year with each one switching off before the next enables.

mm2270
Legendary Contributor III

I was going to suggest something similar to what @mdp suggests above. Only difference is I would probably not capture the date of last execution as an Extension Attribute. I'd just code it into the script in the policy to first check for a last run date from the local file/plist, and if it has been 60 or more days since the last run, then it would continue. If it's less than 60 days, then just exit. You'll have to do a little math in your script, but it's fairly simple to do. Your policy can be set to run once per month, or perhaps once per week would make more sense. It should only then execute the rest of the script if the time since the last execution is 60 or more days, or whatever value you choose.