This one has me stumped. In the past when I've needed to run a bash script as the logged in end user I've simply used something along the lines of:
userName=$(stat -f %Su /dev/console)
sudo -u $userName -H bash -c "jamf recon"
This method seems to still work just fine IF I manually call the policy (jamf -policy) or manually initiate an inventory update (jamf recon) but when it's called with the recurring policy action or daily recurring inventory action it fails, and seems to run as root. So:
- Logged in as sjobs, run 'jamf -policy' = Success, policy executes, relevant lines will successfully run as sjobs
- Logged in as sjobs, run 'jamf recon' = Success, EA executes, relevant lines will successfully run as sjobs
- Logged in as sjobs, Mac is not asleep or unattended, recurring policy trigger occurs in background = Failure, policy executes, relevant lines run as root
- Logged in as sjobs, Mac is not asleep or unattended, recurring inventory trigger occurs in background = Failure, EA executes, relevant lines run as root
Where is the difference in how the script interprets when called via triggers instead of manually via terminal? At first I thought it was a Ventura issue but Big Sur and Monterey behave the same way.