
UNSOLVED
J
JWeinsheimer
91 Posts
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!
Responses (11)
Solutions (0)
sanadminpromutu
8 Posts
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 =)
Reply 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
Reply Try this ::--->
############# Cut Here #############
#### Set the necessary Variables ::--->OLDIFS=$IFSIFS=$'\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
Reply JWeinsheimer
91 Posts
1941
0
Posted February 12th, 2015 10:00
Doesn't full work, but it should put me on the right path. Thanks!
Reply #### 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
Reply 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
Reply 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 Reply JWeinsheimer
91 Posts
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!
Reply

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: