Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > which host

Reply
Thread Tools

which host

 
 
Werner Winter
Guest
Posts: n/a
 
      10-31-2003
Hello,
I've setup a linux terminal server. Now I want to know, which user is logged
in on which host . So I wrote a perl-script named "which_host"

# which user
$uid=$<;
$username=(getpwuid)$uid))[0];
$username = $1;

#which host
@last= `/usr/bin/last -n 1 -a $username`;
# line 18
$host= (split (/\s+/, $last[0]))[9];

The last two lines cause an error: Use of uninitialized value in string eq
at /usr/local/bin/which_host line 18

The problem is, that "last" shows only 8 columns, no host in column 9 is
shown. If I change the line
@last= `/usr/bin/last -n 1 -a $username`;
to
@last= `/usr/bin/last -n 3 -a $username`;
then I get 3 lines and in the third line the host is shown in column 9.

What can I do?

cu
Werner


 
Reply With Quote
 
 
 
 
David Efflandt
Guest
Posts: n/a
 
      10-31-2003
On Fri, 31 Oct 2003, Werner Winter <(E-Mail Removed)> wrote:
> Hello,
> I've setup a linux terminal server. Now I want to know, which user is logged
> in on which host . So I wrote a perl-script named "which_host"
>
> # which user
> $uid=$<;
> $username=(getpwuid)$uid))[0];
> $username = $1;


Doesn't the above throw an error (getpwuid)$uid))[0]. Then you
immediately reassign $username (where does $1 get its value from?).
Learn how to copy/paste, so your code examples are not munged by retyping.

> #which host
> @last= `/usr/bin/last -n 1 -a $username`;
> # line 18
> $host= (split (/\s+/, $last[0]))[9];
>
> The last two lines cause an error: Use of uninitialized value in string eq
> at /usr/local/bin/which_host line 18
>
> The problem is, that "last" shows only 8 columns, no host in column 9 is
> shown. If I change the line
> @last= `/usr/bin/last -n 1 -a $username`;
> to
> @last= `/usr/bin/last -n 3 -a $username`;
> then I get 3 lines and in the third line the host is shown in column 9.


On my system, that column only indicates a remote host, and is typically
empty from localhost (local console login, xterm, etc.). So you have to
consider that possibility in your code. Of course the 9th column would be
the [8] item in the [0..8] list.

--
David Efflandt - All spam ignored http://www.de-srv.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to refer a control in the host page from a user control if the host page using masterpage Jerry Qu ASP .Net 1 02-20-2009 07:41 PM
Dane Cook: Great S.N.L. host or GREATEST S.N.L. host? Jojo the 90lb hottie Digital Photography 1 02-14-2007 04:55 AM
Cisco PIX 501 - Port forwarded to an internal host via Static NAT doesn't work from internal host JoelSeph Cisco 9 01-23-2006 03:52 PM
PIX: how to allow 1 host from outside interface to access another host on the inside interface? jonnah Cisco 1 04-21-2004 02:26 PM
request.getHeader("Host") returns wrong host name Orpheus66 Java 0 07-30-2003 02:59 PM



Advertisments