Extension attribute script question - 'is script running in Jamf or not?'

mags
New Contributor II

Hi
I'm busy creating extension attribute scripts, and would like to be able to use the same scripts whether I'm running them in JAMF or independently on our Macs.

When I'm creating a JAMF extension attribute, I obviously need to add the <result></result> tags at the end, whereas if running the same script directly on a mac, I don't need these tags.

Is there a way to check the environment that the script is running in so that I can then choose whether to add the tags or not?

Any ideas welcome!
Cheers,
Mags

1 ACCEPTED SOLUTION

thoule
Valued Contributor II

This command will give the parent process of a script. When running through the JSS, it returns 'sh'. When running locally it returns 'login' or 'sudo' depending on where you're at. I haven't really used this function so I don't know how it would play out, but you might be worth investigating...

PARENT_COMMAND="$(ps -o comm= $PPID)"
echo $PARENT_COMMAND

View solution in original post

2 REPLIES 2

thoule
Valued Contributor II

This command will give the parent process of a script. When running through the JSS, it returns 'sh'. When running locally it returns 'login' or 'sudo' depending on where you're at. I haven't really used this function so I don't know how it would play out, but you might be worth investigating...

PARENT_COMMAND="$(ps -o comm= $PPID)"
echo $PARENT_COMMAND

mags
New Contributor II

Thanks that's a great help - I can definitely use the parent process to specify whether the script is running in jamf