dpasch has asked for the wisdom of the Perl Monks concerning the following question:
Monks, I am new, and do not have a coding/scripting background.
I am looking to turn some commands I run at the command line of a device into a PERL script, and am seeking advice.
The ask:
1. Run a command to collect data.
EXAMPLE:
"list cm device all-properties | grep configsync-ip"
2. Collect ONLY the IPs from the output of the above command, and set them variables.
EXAMPLE OUTPUT:
configsync-ip 1.1.1.1
configsync-ip 1.1.1.2
$csip1 = 1.1.1.1
$csip2 = 1.1.1.2
3. Run another command(s) using the above variables.
EXAMPLE:
tmsh list net self | grep ($csip1) | -A 1
tmsh list net self | grep ($csip2) | -A 1
4. Based on the text containing "all" in the output, form a response to print.
EXAMPLE OUTPUT:
address 1.1.1.1/24
allow-service all <-- This woud trigger a print, with multiple variables collected outside of the ask.
I do not have much code to offer as my starting point. Just the template that the tool I am working in provides.
Thanks in advance for all responses!
#============= your logic goes here ================== # execute commands # collect cs_vlan ip info my $response = $connect->cmd('tmsh list cm device all-properties | gre +p configsync-ip',{-prompt => '#'}); # set ips from output to variables # use variables in additional commands # analyze the output and create resposes for print my $target; if ($response =~ /(\.....d+\.\d+\.\d+\.\d+….)/) { $target = $1; } #================================================= my $2ndresponse =….. …. $connect->cmd('exit'); $connect->disconnect; # PRINT WHATEVER YOU WANT TO SHOW TO POLICIES print "\n$FINALresponse\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: collect, set, and analyze command outputs
by rjt (Curate) on Oct 04, 2019 at 19:17 UTC | |
Re: collect, set, and analyze command outputs
by jcb (Parson) on Oct 04, 2019 at 22:32 UTC |