This is the format I use for spawning a subprocess in the background and have the script go on.
(INSERT COMMAND HERE) &
Yeah tried that didn't seem to work, the script will continue so I can perform other tasks within the script, but I am wanting to end the script completely the jamf run that called it and leave the task running.
For example call caffienate to force the machine awake for a couple of days or similar.
So you want to have a script in a policy kick off another process but be able to end the policy even though that subprocess might still be running?
@iJake
Exactly what I want :)
If you don't need the result back from this subprocess in the policy I would just build a launchdaemon/agent to run this other script for you. It seems much easier than fighting with subprocesses. What is it this subprocess is doing if you can say?
Just conceptualising at the moment...
Currently just looking at caffeinate with a time out mostly.
Pretty much need to be calling it from Casper though as the idea is it will be tied to other Casper related events such as multiple policies that may be called during a maintenance window.
I could have something local already installed that would do what I wanted it to do I suppose, just like the cleanliness of having it all self contained.
I would envision maybe having a policy that runs every hour at check in that is set to check if certain conditions are met or these other scripts have finished their jobs that you could collect the information and kick off anything else either via policy or whatever. I just can't see how having a policy stay running that long is good. You'll have no idea if it's hung or anything as the logs won't submit until it finishes.
I think a launchdaemon is the way to go. I can create and load a launchdaemon from /tmp to execute a script, so the launchdaemon will be deleted automatically on the next reboot and only run once. I've been doing this to kick off a reboot script so Casper can close out the policy and upload logs before the reboot.
I've also tried many options to spin off new threads, but Casper always waits for them to complete.
Sample code for a bash function to spin off a script:
echo '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.company.runscript</string>
<key>UserName</key>
<string>root</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/script.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>' > /tmp/restart.plist
launchctl load /tmp/restart.plist