Copyright © 2010, Juniper Networks, Inc.
The second parameter,
\%opt
If the user does not provide at least one option, provides an invalid option, or provides
the -
option, the script invokes the
h
message to the screen:
my %opt;
getopts('l:p:dx:m:o:h', \%opt) || output_usage();
output_usage() if $opt{h};
The following code defines the
script. The contents of the
specific to the script, and differ for each application.
sub output_usage
{
my $usage = "Usage: $0 [options] <target>
Where:
<target> The hostname of the target device.
Options:
-l <login>
A login name accepted by the target device.
-p <password> The password for the login name.
-m <access>
Access method. It can be clear-text, ssl, ssh or telnet.
Default: telnet.
-x <format>
The name of the XSL file to display the response.
Default: xsl/chassis_inventory_csv.xsl
-o <filename> File to which to write output, instead of standard output.
-d
Turn on debugging.\n\n";
die $usage;
}
The
get_chassis_inventory.pl
command line for the four parameters required by the
discussion of the various functional units follows the complete code sample.
# Get the hostname
my $hostname = shift || output_usage();
# Get the access method
my $access = $opt{m} || "telnet";
use constant VALID_ACCESSES => "telnet|ssh|clear-text|ssl";
output_usage() unless (VALID_ACCESSES =~ /$access/);
# Check for login name. If not provided, prompt for it
my $login = "";
if ($opt{l}) {
$login = $opt{l};
} else {
print STDERR "login: ";
$login = ReadLine 0;
chomp $login;
}
Chapter 9: Writing Junos XML Protocol Perl Client Applications
, specifies that the values are recorded in the
subroutine, which prints a usage
output_usage
output_usage
subroutine for the
definition and the
my $usage
script includes the following code to obtain values from the
%opt
get_chassis_inventory.pl
and
sections are
Where
Options
JUNOS::Device
object. A detailed
hash.
213
Need help?
Do you have a question about the JUNOS OS 10.3 - XML MANAGEMENT PROTOCOL GUIDE 6-30-2010 and is the answer not in the manual?
Questions and answers