HP P6000 Replication Solutions Manager CLI Reference (T3680-96071, June 2012)

B User-written client examples
This appendix contains examples of creating user-written clients to access the CLUI.
Sample Telnet client using Perl
use strict;
use Net::Telnet ();
my ($hostname, $line, $passwd, $pop, $username,
$cmd, $res, $telnet, $port, $prompt, $ mode);
if(@ARGV < 5){
usage();
die "\nincorrect number of arguments\n\n";
}
($cmd) = @ARGV[4];
$hostname = $ARGV[0];
$port = $ARGV[1];
$username = $ARGV[2];
$passwd = $ARGV[3];
$mode = 1;
$telnet = new Net::Telnet (Telnetmode => 1,
Timeout => 600,
Cmd_remove_mode => $mode,
Prompt => '/[>] $/');
$telnet->open(Host => $hostname,
Port => $port);
## Read connection message.
$line = stripLine();
## Send user name.
$telnet->print("$username");
## Send password.
$telnet->print("$passwd");
#read the responses up to this point (ignoring)
readResponse();
#Send the command passed in as an arg
$telnet->print("$cmd");
#remove the command echo
stripLine();
#get and show the response
$res=readResponse();
print("$res\n");
exit;
sub readResponse {
my $resp = "";
$line = "";
while((index($line,">")<0) and (index($line,"Thank you for using")<0) ){
$line = $telnet->get;
$resp = $resp . $line;
}
return $resp;
}
sub stripLine{
$telnet->getline;
}
sub usage {
print "\n\n\*************************************************************************\n\n";
print "Use: clui_telnet_sample.pl <host> <port> <username> <password> <\"command\">\n\n";
print " host - ip or name\n";
48 User-written client examples