Skip to main content
Question

While loop while a policy is running?


Forum|alt.badge.img+8
  • New Contributor
  • 6 replies

Is it possible to execute a while loop in a script while a policy is running? So while x policy runs, do something?

5 replies

sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3536 replies
  • April 24, 2020

@Bko Off the top of my head you could have a script that runs at the beginning of your policy which creates a flag indicating your policy is running (e.g. touch /tmp/MyPolicyIsRunning) then spawns a process for your while loop that looks for that flag to keep running. At the end of your policy run a script that deletes the flag (e.g. rm /tmp/MyPolicyIsRunning)


Forum|alt.badge.img+8
  • Author
  • New Contributor
  • 6 replies
  • April 24, 2020

Oh that's a great idea!


Forum|alt.badge.img+8
  • Author
  • New Contributor
  • 6 replies
  • April 24, 2020
Off the top of my head you could have a script that runs at the beginning of your policy which creates a flag indicating your policy is running (e.g. touch /tmp/MyPolicyIsRunning) then spawns a process for your while loop that looks for that flag to keep running. At the end of your policy run a script that deletes the flag (e.g. rm /tmp/MyPolicyIsRunning)

Actually I'm not sure it'll work now. So what I'm trying to do is to have a while loop that checks the download progress of a large file in a policy. Even with your method, I think, the download would have to be complete before the loop starts or the loop starts before the download begins and would have to break.

The idea is as long as the policy is running, to check how much of the file has downloaded, compare it to the end file size, and output it within (replacing) the jamf helper window that is already up. I'm trying to keep cocoa dialogue or any other programs, out of it.


Forum|alt.badge.img+6
  • Contributor
  • 24 replies
  • April 25, 2020

You can try to put everything under a script.
You could first trigger the caching or download policy adding a & at the end so the script continues and add the while loop afterwards to monitor the download process.

#!/bin/zsh
jamf policy -event downloadMyBigPkg &

Once done you can do your checks and exit the script.


sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3536 replies
  • April 27, 2020

@Bko If you have a Script payload set to run "Before" it should execute before the download of any Package payloads in your policy. You would need to expand your logic in the spawned script to wait for the download to begin while the /tmp/MyPolicyIsRunning flag is in existence since the download may not have started when your script starts, but that flag indicates it's expected.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings