On Friday, June 7, 2002, at 11:28 , Shishir K. Singh wrote:
> But I want something akin to the value of $REMOTEHOST under tcsh. This
> can be generalized under unix by doing
which is of course useful only to those running tcsh.... 8-)
[..]
> but will not work under non Unix envi. Here comes in the perl. I was
> hoping for something which is shell/platform independent.
[..]
vladimir: 58:] who -m
drieux pts/1 Jun 7 11:56 (jeeves)
vladimir: 61:] who -m | perl -e 'print "$1\n" if (<STDIN>=~m/\((.*)\)/);'
jeeves
vladimir: 62:]
the problem of the 'platform independence' is that the
underlying OS will be a bit of an issue - the above if it
does not have something like 'who' to begin with - and
it's generically safer to run the 'who -m' trick.
> On Friday, June 7, 2002, at 09:41 , Shishir K. Singh wrote:
>
>> I have a requirement to get the IP address of a user logged from a remote
>> machine on to UNIX machine. Now the user can be using multiple logins
>> through VPN or otherwise. I need to create something akin to command
>> "finger" which will return the user his IP address based on his current
>> session.
my bad - there is the critical sentence
'will return the user his IP address'
hence you would want something like:
#!/usr/bin/perl -w
# IamFrom - uses the whoCmd to return where they came from
use strict;
use Config;
my $whoCmd = ($Config{osname} eq "Win32")? "specialWin32Cmd":"who -m";
my $line;
open(INFO1, "$whoCmd |") or die "can not get who:$!\n";
print "$1\n" if (< INFO1 >=~m/\((.*)\)/);
close INFO1 ;
exit(0);
[..]
I have seen folks try to do thing like use this sort of process
to do the game of
setenv DISPLAY `who -m | perl -e 'print "$1:0\n" if
(<STDIN>=~m/\((.*)\)/);'
only to have their xterms go to hosts they just telnetted from
because, they came from say 'wetware' vice 'jeeves' - and what
they wanted was the xterm to show up on jeeves:0.....
so I tend to recommend against those types of things....
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]