Hello.

Here are some scripts which I wrote in the past few
days.
Please take a look and give me some feedback.

-- Ashish
#!/usr/local/bin/perl -w

use strict;
use Sys::Utmp;

if (scalar @ARGV > 2)
{
	usage();
}
elsif ($ARGV[0] =~ /am|are/i && $ARGV[1] =~ /i|you/i)
{
	print $ENV{USER},"\n";
} 
else	
{
	display_info($ARGV[0]);
}

sub usage
{
	 print "who [ who-file ] [ am I ] [ are you ]\n";
}

#### Accept optional filename argument and display who info ##### 

sub display_info
{
	my $file = shift;
	my %args = ($file) ? (Filename => $file) : ();

	die "$0: $file: No such file\n" if ($file && ! (-e "$file" && -r "$file"));

	my $utmp = Sys::Utmp->new(%args);

	print "User\tLine\tTime\n";

	while ( my $utent =  $utmp->getutent() )
	{
		my $user = $utent->ut_user;
		print $user,"\t",$utent->ut_line,"\t",scalar localtime ($utent->ut_time),"\n" 
			if ($utent->user_process && $user);	
	}

	$utmp->endutent;
}

__END__

=head1 NAME

who - display who is on the system

=head1 SYNOPSIS

who [ who-file ] [ am I ] [ are you ]

=head1 DESCRIPTION

The who utility displays information about currently logged in users.  By default, this includes the login name, tty name, date and time of login. By default, who gathers information from the file /var/run/utmp but an alternate file can be specified as the first argument to the command.

The options are as follows:

am i	Show info about terminal attached to STDIN only.

are you Equivalent to "am i"

=head1 ENVIRONMENT

The working of who is not affected by an environment variables.

=head1 SEE ALSO

getuid(2), utmp(5) 

=head1 HISTORY 

A who command appeared in Version 1 AT&T UNIX

=head1 AUTHOR

The Perl implementation of who is written by Ashish Mukherjee, [EMAIL PROTECTED]
#!/usr/local/bin/perl -w

use strict;

my $login = getpwuid($>);
print $login,"\n";

__END__

=head1 NAME

whoami - display effective user ID 

=head1 SYNOPSIS

whoami

=head1 DESCRIPTION

The whoami utility has been obsoleted by the id(1) utility, and is equivalent to id -un. The whoami utility displays your effective user ID as a name.

The whoami utility exits 0 on success or >0 if an error occurred.

=head1 SEE ALSO

id(1)

=head1 AUTHOR

The Perl implementation of whoami is written by Ashish Mukherjee, [EMAIL PROTECTED]
#!/usr/local/bin/perl -w

use strict;

use Sys::Utmp;

my @users;

my $utmp = Sys::Utmp->new();
while ( my $utent =  $utmp->getutent() )
{
	my $user = $utent->ut_user;
	push @users, $user if $user;
}

print join(" ", sort @users),"\n";

__END__

=head1 NAME

users - list current users

=head1 SYNOPSIS

users

=head1 DESCRIPTION

The users utility lists the login names of the users currently on the system, in sorted order, space separated, on a single line.

=head1 FILES

/var/run/utmp

=head1 SEE ALSO

finger(1), last(1), who(1), utmp(5)

=head1 HISTORY

The users command appeared in 3.0BSD.

=head1 AUTHOR

The Perl implementation of users is written by Ashish Mukherjee, [EMAIL PROTECTED]
#!/usr/local/bin/perl -w

use strict;

my $login = getpwuid($>);
print $login,"\n";

=head1 NAME

logname - display user's login name

=head1 SYNOPSIS

logname

=head1 DESCRIPTION

The logname utility writes the user's login name to standard output fol-
lowed by a newline.

The logname utility explicitly ignores the LOGNAME and USER environment
variables because the environment cannot be trusted.

=head1 DIAGNOSTICS

The logname utility exits 0 on success, and >0 if an error occurs.

=head1 SEE ALSO

who(1), whoami(1), getlogin(2)

=head1 STANDARDS

The logname function is expected to conform to IEEE Std 1003.2 (``POSIX.2'').

=head1 HISTORY

The logname command appeared in 4.4BSD.

=head1 AUTHOR

The Perl implementation of logname is written by Ashish Mukherjee, [EMAIL PROTECTED]

Reply via email to