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
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".
ionthegeek
2 Intern
•
2K Posts
0
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:
sanadminpromutu
8 Posts
0
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
0
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.
Regards, César
jdespres
2 Intern
•
176 Posts
1
February 8th, 2015 20:00
Try this ::--->
############# Cut Here #############
IFS=$'\n'
DataFile=`hostname`_retentions.txt`
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
JWeinsheimer
91 Posts
0
February 12th, 2015 10:00
Doesn't full work, but it should put me on the right path. Thanks!
jdespres
2 Intern
•
176 Posts
0
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
0
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
0
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
}
ionthegeek
2 Intern
•
2K Posts
1
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".
JWeinsheimer
91 Posts
1
February 12th, 2015 12:00
I was able to get it working using xml parsing and the following...
Where file1 and file2 are the parsed xml outputs.
Thanks a ton!
jdespres
2 Intern
•
176 Posts
0
February 12th, 2015 13:00
I like quick & dirty.....
But you do have a point!
I will need to learn how to interface Avamar's API's....
good luck to me
Thanks
Joe Despres