Disk Enclosures
cancel
Showing results for 
Search instead for 
Did you mean: 

HP P2000 CLI perl scripting error

SOLVED
Go to solution
viswasarathy rajasekara
Occasional Visitor

HP P2000 CLI perl scripting error

Hi friends,

I am trying to write a perl script using HP P2000 CLI library to create snapshots and map the snapped volume to host before nightly backup and delete the snapshots after the backup is complete.

I refered HP P2000 CLI reference guide to script this functionality.
http://bizsupport1.austin.hp.com/bc/docs/support/SupportManual/c02520779/c02520779.pdf
(page: 14 & 15)

I installed perl software locally in my desktop.

I used below script to connect to storage system and trying to execute "Show configuration" cli command to start with. When i execute the below script. I am getting the "command timed-out at line login.pl in 35". Can any one help out to resolve this?

Perl script: login.pl
---------------------
use Net::Telnet;
sub cLogin {
$telnet->open($_[0]);
$telnet->waitfor(/(login|username)[: ]*$/i);
$telnet->print("$_[1]");
$telnet->waitfor(/password[: ]*$/i);
$telnet->print("$_[2]");
# either got a login or a prompt
@ok = $telnet->waitfor(/(#|login:*) /i);

if ($debug_commands == 1) { print "-"; print @ok; print "-\n"; }
if ($ok[1] =~ m/login/gi)
{
return 0;
}
else
{
return 1;
}
}
$ipAddr = $ARGV[0];
$username = $ARGV[1];
$password = $ARGV[2];
$telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die');
if ( !cLogin('000.000.00.0000','johnsmith','smithpass') == 1 )
{
print("Error: $username user failed to log in. Exiting.\n");
$telnet->close;
exit(0);
}else{
print("Info: Login successfull.\n");
@test = $telnet->cmd("show configuration");
print @test;

for ($i=0; $i{
print ("@test[ $i ]");
}
}


Output
------
C:\Perl\eg>perl login.pl
Info: Login successfull.
command timed-out at login.pl line 32


Thanks in advance,
Viswa










4 REPLIES
Daniel Ruppert
Occasional Visitor
Solution

Re: HP P2000 CLI perl scripting error

Hi Viswa,

i faced exactly the same problem. But i think i found a solution. You have to throw away the hole script and define the Prompt.

1.) HP thinks too complicated... :-)
2.) try this:

use Net::Telnet;

$TARGET_IP = $ARGV[0];
$USER = $ARGV[1];
$PASSWORD = $ARGV[2];

$telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die',Prompt => '/\# $/i');
$telnet->open($TARGET_IP);
$telnet->login($USER, $PASSWORD);
print $telnet->cmd('show configuration');

For me this works.

cu
Daniel
viswasarathy rajasekara
Occasional Visitor

Re: HP P2000 CLI perl scripting error

Hi Daniel,

Your code simple and easy. Thanks for your response.

After a try we got this below to work as well.

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die',Prompt => '/\# $/i');
$return = 0;
@chkLgn = cLogin("150.123.70.172", "MLC_Admin", "metapass");

if ( !chkLgn == 1 )
{
print("Error: $username user failed to log in. Exiting.\n");
$telnet->close;
exit(0);
} else {

executeCmd("show volumes");
$telnet->close;
exit($return);
}




sub cLogin {
$telnet->open($_[0]);
$telnet->waitfor('/(login|username)[: ]*$/i');
$telnet->print("$_[1]");
$telnet->waitfor('/password[: ]*$/i');
$telnet->print("$_[2]");
# either got a login or a prompt
@ok = $telnet->waitfor('/(#|login:*) /i');
if ($debug_commands == 1) {
print "-";
print @ok;
print "-\n";
}

if ($ok[1] =~ m/login/gi)
{
return 0;
}
else
{
return 1;
}
}


sub executeCmd {

@sV = $telnet->cmd("$_[0]");
for ($i=0; $i {
if("@sV[ $i ]" !~ /Error/){
print ("@sV[ $i ]");
} else {
$return = 1;
}
}

}

Thanks Again
-Viswa

cssanangeles
Occasional Visitor

Re: HP P2000 CLI perl scripting error

anybody have any SSH script to the SAN storage I can use? I tried expect,openssh and nothing work, kept getting

this error when I use a command like "show vdisks"

 

Received disconnect from ipaddress: 2: unsupported command

cssanangeles
Occasional Visitor

Re: HP P2000 CLI perl scripting error

btw I can't use Telnet, our IT guys disable telnet.