Policy script works when manually triggered but fails on ongoing event...

tulgeywood
New Contributor

I have created a very simple script that tells an application to generate a text log. A policy is in place to run this script as a part of the ongoing checkin.

#!/bin/sh
sudo promiseutil -C phydrv > /PegasusLog/log.txt

If I run sudo jamf policy in terminal it will successfully create the log.txt file with the appropriate output. Once the computer checks back in to the JSS though and tries to execute the script it will exit with exit code 5. It also overwrites the log.txt file with a blank log.txt file. What am I missing here?

3 REPLIES 3

m_entholzner
Contributor III
Contributor III

First, you don't need to write a "sudo" in a bash script because all scripts are run as root. Add a second ">" for your output to get the log added to a text file. AND, just to create a clean script, add an exit code to your script.
Your command should look like these:

#!/bin/sh
promiseutil -C phydrv >> /PegasusLog/log.txt
exit 0

tulgeywood
New Contributor

Thanks for the input. It is still creating a blank text file when the computer checks into the JSS. If I do a jamf policy command though it will create the file correctly. Additionally, I didn't use >> because I don't want it to be a running log. Just a status. Any other ideas as to what could going on? I appreciate the help, I'm a python person so bash makes me unhappy.

m_entholzner
Contributor III
Contributor III

Still a few things to test :)
Please try the following:

Change the path to promiseutil to the full path. Perhaps the output of the promiseutil is on the error channel, so redirect all outputs:
/path/to/promiseutil -C phydrv 2>&1 > /PegasusLog/log.txt