Posted on 04-23-2020 03:31 PM
Is it possible to execute a while loop in a script while a policy is running? So while x policy runs, do something?
Posted on 04-23-2020 06:52 PM
@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
)
Posted on 04-24-2020 09:25 AM
Oh that's a great idea!
Posted on 04-24-2020 11:24 AM
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.
Posted on 04-25-2020 08:05 AM
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.
Posted on 04-26-2020 07:58 PM
@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.