#!/usr/bin/perl
#
# host [id args...]
#
# This is an rlogin script.  It should be linked to one or  more  host
# names,  so  you  just  need  to  type  the hostname.  A new xterm is
# started, and if an id is given on  the  command  line,  it  will  be
# passed  to the rlogin command.  Any extra args will be passed to the
# xterm, so you can control things like the font size and color.
# If there is no arg on the command line, we look up the host name in
# $HOME/.netrc and use the name on the first match.

($host = $0) =~ s#.*/##;	# Cut off any directory from our name.

if ($id = $ARGV[0]) {	# First arg is user id.
	shift(ARGV);
} else {		# No user id on command line.
	if (open(N,"<$ENV{'HOME'}/.netrc")) {
		for (<N>) {
			if (/^${host}\s+(\w+)/) {
				$id = $1;
				last;
			}
		}
	} else {	# Get user id from environment.
		$id = $ENV{'USER'} || $ENV{'LOGNAME'} || 'anonymous';
	}
}

system "Xterm @ARGV -e telnet $host &";

