UNSOLVED

JWeinsheimer

updated

12 years ago

0

2981

February 6th, 2015 05:00

MCCLI Scripting Question

Perhaps the best way for me to explain this is with an example...

When I run mccli retention show --recursive --verbose I get:

0,23000,CLI command completed successfully.

Name                         Domain          Expiration    Override

---------------------------- --------------- ------------- --------

Default Retention            /               60 days       Yes

Desktop Retention            /               14 days       No

End User On Demand Retention /               60 days       No

Minimal Retention            /               No expiration No

Monthly Retention            /               1 month       No

Weekly Retention             /               1 week        No

TopC Advanced Dataset        /TopA/TopB/TopC 60 days       Yes

When I run mccli retention show --domain=/TopA/TopB/TopC --name="TopC Advanced Dataset" --recursive --verbose I get:

0,23000,CLI command completed successfully.

Attribute              Value

---------------------- ---------------------

Name                   TopC Advanced Dataset

Domain                 /TopA/TopB/TopC

Basic Expiration Date  60 days

Override               Yes

Keep DAYS of Daily     60

Keep WEEKS of Weekly   12

Keep MONTHS of Monthly 52

Keep YEARS of Yearly   3

Is there any way to run one command, like the first one, and export all the details for each policy like the second one? Or do I have to do some sort of scripting to take the first output and generate multiple commands for the second?

Thanks!

  • ionthegeek

    2 Intern

    •

    2049 Posts

    1934

    0

    Posted February 6th, 2015 09:00

    I don't believe this can be done using a single command but you may find it helpful to retrieve the first output in xml format (by specifying the --xml flag) so you don't have to do screen-scraping or RegEx matching. Here is an example of the XML format:

    admin@testavamar:~/#: mccli retention show --recursive --verbose --xml

     

        0

        23000

        CLI command completed successfully.

     

     

       

          Default Retention

          /

          60 days

          Yes

       

       

          End User On Demand Retention

          /

          60 days

          No

       

       

          Ian_Test

          /

          65 days

          No

       

       

          Minimal Retention

          /

          No expiration

          No

       

       

          Monthly Retention

          /

          1 month

          No

       

       

          Weekly Retention

          /

          1 week

          No

       

     

  • 1939

    0

    Posted February 6th, 2015 12:00

    The way I do it is I query the PostgreSQL database with a python script, and loop over the result of the first query.

    But Ian is right, using XML would make more sense. All of these answer assume your scripting skills are up to date =)

  • Cbueno1

    22 Posts

    1939

    0

    Posted February 8th, 2015 05:00

    Hi JWeinsheimer,

    You can use this command. But only works if retention name have not spaces. This is a good starting point for improvement.

    mccli retention show --domain=/ --recursive=true | grep "/" | awk '{print $1,$2}' | while read c d; do echo "$d/$c"; mccli retention show --domain=$d --name=$c --verbose; done

    Regards, César

  • jdespres

    2 Intern

    •

    176 Posts

    1939

    1

    Posted February 8th, 2015 20:00

    Try this ::--->

    ############# Cut Here #############

    #### Set the necessary Variables ::--->
    OLDIFS=$IFS

    IFS=$'\n'

    DataFile=`hostname`_retentions.txt`

    #### Generate retention xml file ::--->

    mccli retention show --recursive --verbose --xml > `hostname`_ret.xml

    #### Parse out xml info info ::--->

    awk -F'' '{for(i=2;i<=NF;i++) print $i}' `hostname`_ret.xml |sed '/^$/d'  >one.txt

    awk -F'' '{for(i=2;i<=NF;i++) print $i}' `hostname`_ret.xml |sed '/^$/d' >two.txt

    #### Combine both files created ::--->

    paste -d/ one.txt two.txt|sed 's/\/\//\//g' > $DataFile

    #### Loop tru the final collected data ::--->

    for i in `cat $DataFile`; do echo "*** $i ***";mccli retention show --name=$i --verbose|sed '1,1d'; done


    #### Unset the necessary Variables ::--->

    IFS=$OLDIFS


    ############# Cut Here #############


    Thanks....


    Joe Despres

  • 1941

    0

    Posted February 12th, 2015 10:00

    Doesn't full work, but it should put me on the right path. Thanks!    

  • jdespres

    2 Intern

    •

    176 Posts

    744

    0

    Posted February 12th, 2015 12:00

    #### Example output ::--->

    :~/DataFiles/>: ret

    *** /Default Retention ***

    Attribute              Value

    ---------------------- -----------------

    Name                   Default Retention

    Domain                 /

    Basic Expiration Date  60 days

    Override               Yes

    Keep DAYS of Daily     60

    Keep WEEKS of Weekly   0

    Keep MONTHS of Monthly 0

    Keep YEARS of Yearly   0

    *** /End User On Demand Retention ***

    Attribute             Value

    --------------------- ----------------------------

    Name                  End User On Demand Retention

    Domain                /

    Basic Expiration Date 60 days

    *** /Minimal Retention ***

    Attribute             Value

    --------------------- -----------------

    Name                  Minimal Retention

    Domain                /

    Basic Expiration Date No expiration

    Disabled              Yes

    *** /Monthly Retention ***

    Attribute              Value

    ---------------------- -----------------

    Name                   Monthly Retention

    Domain                 /

    Basic Expiration Date  1 month

    Override               No

    Keep DAYS of Daily     60

    Keep WEEKS of Weekly   0

    Keep MONTHS of Monthly 0

    Keep YEARS of Yearly   0

    *** /Repl Group 1 Repl Expiration ***

    Attribute              Value

    ---------------------- ----------------------------------

    Name                   Repl Group 1 Repl Expiration

    Domain                 /

    Basic Expiration Date  No change (keep backup expiration)

    Override               No

    Keep DAYS of Daily     60

    Keep WEEKS of Weekly   0

    Keep MONTHS of Monthly 0

    Keep YEARS of Yearly   0

  • jdespres

    2 Intern

    •

    176 Posts

    1939

    0

    Posted February 12th, 2015 12:00

    I learned two pieces of info here....

    1:  How to handle spaces ...

    2:  How to parse a xml file...

    Joe Despres

  • jdespres

    2 Intern

    •

    176 Posts

    1941

    0

    Posted February 12th, 2015 12:00

    Try this function ::--->

    ret () {
    OLDIFS=$IFS
    IFS=$'\n'
    DataFile=`hostname`_retentions.txt
    mccli retention show --recursive --verbose --xml > `hostname`_ret.xml
    awk -F'' '{for(i=2;i<=NF;i++) print $i}' `hostname`_ret.xml |sed '/^$/d'  >one.txt
    awk -F'' '{for(i=2;i<=NF;i++) print $i}' `hostname`_ret.xml |sed '/^$/d' >two.txt
    paste -d/ one.txt two.txt|sed 's/\/\//\//g' > $DataFile
    for i in `cat $DataFile`; do echo "*** $i ***";mccli retention show --name=$i --verbose|sed '1,1d'; done
    IFS=$OLDIFS
    }

    Then run it ::--->
    ret

  • ionthegeek

    2 Intern

    •

    2049 Posts

    1377

    1

    Posted February 12th, 2015 12:00

    Relevant, re: parsing XML:

    http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

    I always recommend using a real XML parser for XML but I understand why quick and dirty is appealing (and I have occasionally committed this sin myself when I'm in a hurry).

    I'd recommend using an XML parsing module in a scripting language like Perl, Python, Ruby, etc. if you plan to rely on this tool for anything "production-y".

    Language XML Parsers
    Perl XML::Parser, XML::Simple
    Python xml.dom, xml.sax
    Ruby ReXML, Nokogiri
  • 1939

    1

    Posted February 12th, 2015 12:00

    I was able to get it working using xml parsing and the following...

    LINE=0

    cat file1 | while read VAR1

      do

        let LINE=$LINE+1

        VAR2=$(cat file2 | sed -n ${LINE}p)

        echo $VAR1 $VAR2

    done

    Where file1 and file2 are the parsed xml outputs.

    Thanks a ton!