Skip to main content
Solved

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

  • July 18, 2017
  • 2 replies
  • 22 views

Forum|alt.badge.img+3

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

Best answer by thoule

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

2 replies

Forum|alt.badge.img+15
  • Contributor
  • Answer
  • July 18, 2017

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

Forum|alt.badge.img+3
  • Author
  • New Contributor
  • July 19, 2017

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