HP StorageWorks 2300 Modular Smart Array CLI reference guide (500912-001, January 2009)

HP StorageWorks 2300 Modular Smart Array CLI reference guide 13
The following example shows how to construct a script using a Perl library for Telnet communication.
use Net::Telnet;
$mVer = "v.072006";
$mLine = "==========================================================";
$mStr = "Management Controller System Cloning Utility";
$nLine = "\n";
$cliDumpFile = "get_config_dump.txt";
$space = ' ';
$username = "";
$password = "";
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_comamnds == 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',
Prompt => '/\# $/i');
if ( !cLogin($ipAddr, $username, $password) == 1 )
{
print("Error: $username user failed to log in. Exiting.\n");
$telnet->close;
exit(0);
}
The above shows a Perl script for logging in. cLogin is called at the start of the script to log a user into the
CLI. The script uses the command-line parameters specified as the IP address, username, and password.
Once the user has been logged in, other commands can be sent to the CLI.
For better scripting support, you can change the CLI output mode from its default mode, console, which
produces human-readable output, to api, which produces XML output.
In the following command, the first argument sets the output format to XML, which allows easier parsing.
The second argument disables the paging mode that pauses for each full screen of command output.
$telnet->cmd("set cli-parameters api pager disabled");
The following code segment shows how to get the entire configuration information from the CLI and print
the output. The output can easily be redirected to a file for archiving.
@sV = $telnet->cmd("show configuration");
for ($i=0; $i<scalar(@sV); $i++)
{
print (“@sV[ $i ]”);
}
The next section provides more information about using the XML API.