#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;
use Net::Telnet;

my $logpath  = "/root/switchmgr/log";
my $swpw     = "keklolwtf";
my $switch   = "$ARGV[0]";
my $domain   = "internal";
my $usepw    = 0;
my @cmds     = @ARGV;

my $session = new Net::Telnet(Timeout    => 5,
                              Telnetmode => 0,
                              Prompt     => '/'.$switch.'.*?# /',
                              Dump_log   => "$logpath/telnet_procurve.debug",
                              Host       => "$switch.$domain"
    );

$session->waitfor('/Press any key to continue/');
$session->print("");

if ($usepw) {
    $session->waitfor('/Password: /');
    $session->print($swpw);
}
    
$session->waitfor('/'.$switch.'.*?# /');
    
# Avoid the "more" prompt for long output.
$session->cmd(String => "terminal length 1000");

# Execute commands
foreach my $cmd (1 .. $#cmds) {
        print $session->cmd(String => "$cmds[$cmd]");
}

$session->close;