#!/usr/bin/env perl

# Copyright (C) 2009  Joshua Hoblitt

use strict;
use warnings FATAL => qw( all );

use vars qw( $VERSION );
$VERSION = '0.01';

use Config::YAML;
use Console;

use Getopt::Long qw( GetOptions :config auto_help auto_version );
use Pod::Usage qw( pod2usage );

my (
    $user,
    $verbose,
);

GetOptions(
    'user|u=s'  => \$user,
    'verbose|v' => \$verbose,
) || pod2usage( 2 );

my $hostname = shift @ARGV;
die "a hostname is required" unless defined $hostname;

$user ||= $ENV{USER};

my $rcfile = Console::find_rcfile();
my $c = Console::read_rcfile($rcfile);
my $hosts = $c->get_hosts;

my $console = $hosts->{$hostname}->{console};
die "error with rcfile: $rcfile, console for $hostname is not defined"
    unless defined $console;

my $cmd = "ssh $user:$hostname\@$console";
print $cmd, "\n" if $verbose;
system($cmd);

__END__

=pod

=head1 NAME

console - access a remote serial console

=head1 SYNOPSIS

    console [--user <username>] [--verbose] <hostname>

=head1 DESCRIPTION

This program looks for mounted volumes, at a configurable interval, and records
statistics about them into a database.

=head1 OPTIONS

=over 4

=item * --user|-u

The C<ssh> username to use when connecting to the console port.

=item * --verbose|-v

Turns on informational/debugging messages to be sent to the
C<stderr>/C<stdout>.

=back

=head1 RCFILE

This program will attempt to read an C<rcfile> from F<$HOME/.Consolerc>.

=head1 CREDITS

Just me, myself, and I.

=head1 SUPPORT

Please contact the author directly via e-mail.

=head1 AUTHOR

Joshua Hoblitt <jhoblitt@cpan.org>

=head1 COPYRIGHT

Copyright (C) 2009  Joshua Hoblitt.  All rights reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA  02111-1307, USA.

The full text of the license can be found in the L<perlgpl> Pod as supplied
with Perl 5.8.1 and later.

=head1 SEE ALSO

L<Config::YAML>, L<Console>, L<console-config>, L<console-ipp-defaults>

=cut
