Thanks, Jeff.
It's not clean that there's any other process link between
Terminal.app or iTerm.app
and the shell processes running in their windows, but that's the
sort of thing I was
looking for. I'm still interested, from a theoretical unix-plumbing
POV, whether there
is a way to trace the owner thru some process info, but I found the
practical solution:
It turns out that SOMETHING is putting that into into an
environment variable.
Typing 'env' shows either:
TERM_PROGRAM=Apple_Terminal
or
TERM_PROGRAM=iTerm.app
Maybe the Terminal.app authors realized that it was going to be
difficult to backtrace
the owner from the shell, and decided to stick it in there, and the
iTerm folks followed
that hint. (Or is this some convention that xterm started ?? )
-- Steve Majewski / UVA Alderman Library
On Dec 19, 2007, at 12:02 PM, jeff donovan wrote:
> On Dec 19, 2007, at 11:44 AM, Steven D. Majewski wrote:
>
>> I've got a small shell script that executes an applescript via
>> osascript
>> to set the terminal background & foreground colors ( looking them
>> up in
>> /usr/X11R6//lib/X11/rgb.txt if they are names rather than numbers. )
>>
>> I would like to extend this script to work with iTerm.
>>
>> Any ideas on the best way to figure out whether Terminal.app or
>> iTerm.app
>> is the 'owner' of the tty where the shell script is executing ?
>>
>> The only way I can think of is using 'lsof' , and that seems like
>> a pretty
>> indirect route:
>>
>> $ tty
>> /dev/ttyp1
>>
>> $ lsof -c Terminal | grep '/dev'
>> Terminal 238 sdm7g 0r VCHR 3,2 0t0 42135940 /dev/
>> null
>> Terminal 238 sdm7g 1w VCHR 0,0 0t906 42136580 /dev/
>> console
>> Terminal 238 sdm7g 2w VCHR 0,0 0t906 42136580 /dev/
>> console
>> Terminal 238 sdm7g 11u VCHR 5,1 0t2701 42376836 /dev/
>> ptyp1
>>
>>
>> The shell's tty and Terminal.app's pty are the slave/master pair
>> of pseudo
>> terminal devices -- different names, but I'm guessing the last
>> digits will
>> always match up.
>>
>>
>> Any other ideas ?
>>
>> -- Steve Majewski / UVA Alderman Library
>
>
>
> greetings
>
> Just a thought; i do this with my ssh connections
>
> do shell script " whoami "
> root
>
> scan ps -aux for the tty or process and it will list the user
> connections.
>
> ps -aux | grep ssh
>
> root 10310 0.0 -0.1 30316 1100 ?? S 11:46AM
> 0:00.08 /usr/sbin/sshd -i
>
>
> another is as the user ps the user processes.
> example.
> nc1-100:~ drfoo$ ps
> PID TTY TIME CMD
> 15450 ttys000 0:00.01 -bash
> 15459 ttys001 0:00.01 -bash
> 15504 ttys001 0:00.39 ssh -l root mail2
>
> or something like that.
>
> man ps for more ideas.
|