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

print " port - the port the clui is on\n";
print " username - admin user name\n";
print " password - admin password\n";
print " command - the command to send via the clui - in quotes\n\n";
print "*************************************************************************\n";
} # end sub usage
Sample socket client using Perl
#Copyright: Copyright (c) 2003
#Company: Hewlett-Packard Company
use strict;
use IO::Socket;
my ($hostname, $line, $passwd, $username, $res, $sock, $port,
$cmd);
if(@ARGV < 5){
usage();
die "\nincorrect number of arguments\n\n";
}
$hostname = $ARGV[0];
$port = $ARGV[1];
$username = $ARGV[2];
$passwd =
$ARGV[3];
$cmd = $ARGV[4];
# want to jump timeout if slow connection or remote server
#blocks for longer than timeout val when zipping server files
$sock = new IO::Socket::INET (
PeerAddr $hostname,
PeerPort => $port,
Proto => 'tcp',
Timeout => 60
);
die "Could not create socket: $!\n" unless $sock;
print $sock "LOGIN USERNAME=$username PASSWORD=$passwd\r\n";
#read the telnet login handshake and discard
readResponse();
#Send command passed in via arg
$sock->print($cmd . "\r\n");
$line = readResponse();
print("$line\n");
#close our socket
$sock->close();
#exit success if we make it here
exit 0;
#
sub getResponse{
#WARNING - this will block if line is not available
my $ret = "";
$ret = readline $sock;
return $ret;
}
#sub to find the </commandresponse> string that is found
#after setting result type to xml
sub readResponse {
my $resp = "";
my $buff = '';
$line = "";
while(index($resp, "</commandresponse>") < 0){
recv($sock, $buff, 1024, 0);
$line = unpack("a1024", $buff);
$resp = $resp . $line;
#print("$line\n");
}
return $resp;
}
Sample socket client using Perl 49