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";

In reply to collect, set, and analyze command outputs by dpasch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.