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?

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.

  • 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 Dec 19 '12 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 Dec 19 '12 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 Dec 21 '12 at 8:11

This site is temporarily in read only mode and not accepting new answers.

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