3

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?

1 Answer 1

4

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.

3
  • Thanks, I may resort to that - though I had been hoping that I could seamlessly use the same script in both places - it needs to act differently in each place. I'm looking through the environment variables, and may have found a couple options that may be sufficient for my needs (COLUMNS or TERM) - though I'm still interested in a proper method, if it exists...
    – Scot
    Commented Dec 19, 2012 at 5:37
  • @Scot Here's an example of parsing arguments from a shell script if you're not familiar with that side of scripting.
    – bmike
    Commented Dec 19, 2012 at 23:25
  • Thanks again. For the purposes of this script, I wanted to have the logic built-in to the script itself, so I ended up using the environment variable TERM (it is dumb when running a script within ARD, and xterm-256color when running locally. So far this has been a good enough hook...
    – Scot
    Commented Dec 21, 2012 at 8:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .