Detecting that a script is run within ARD Does anyone know of a way to detect that a shell script is running within ARD (vs. running the same script locally on the machine)?

I looked at detecting that we are running in interactive mode - that fails, since both are noninteractive.

I'm looking at the $0 variable, which looks more promising - it returns -bash when run from the command line, returns the name of the script when running within a script run locally, and returns /bin/bash when run via ARD. However - I'm not certain whether those effects can be counted on.

Does anyone have any input on this?
Why not pass in an extraneous argument when you issue a command from ARD. 

It's more a workflow than a system generated tag, but ARD likely sends the same command to launchd as the open -a command would so that level of indirection means that you can't depend on the typical ppid from ps -ef to find the process that forked a specific script.

Why not push a wrapper script to all your machines and use that wrapper script to log the arguments to console? Then ARD can call the wrapper script.

Something like a script stored in /usr/local/bin/remote would work well:

#!/bin/bash
echo "This script was called remotely and is about to run another script."
/bin/bash $*
echo "This script has just run another script."


You can get all fancy with parsing the arguments or using logger and/or date/time stamping or recording which computer did the sending, but this is a common way to track execution of other scripts.