Skip to content

Instantly share code, notes, and snippets.

@matthewbednarski
Created August 21, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewbednarski/5c8ea14649583e7e97f6 to your computer and use it in GitHub Desktop.
Save matthewbednarski/5c8ea14649583e7e97f6 to your computer and use it in GitHub Desktop.
A shell script for remotely extracting and parsing xml files from zip archives (such as .jar/.war/.ear archives )
#!/bin/bash
##############
#
#
# Get applicationContext.xml
# depends: 7z, ssh
#
#
##############
ssh_conn=$1
file_to_get=$2
remote_archive_path=$3
out_file=$4
ssh $ssh_conn "unzip -p $remote_archive_path $file_to_get" > $out_file
##############
#
#
# list repo ids
# depends: xmllint
#
# example of an xpath //*[local-name()='map'][@id='connectionBeanProperties']/*[local-name()='entry'][@key='repositoryUniqueId']/@value
#
##############
function xpath {
local xpath=$1
local xml=$2
xmllint --xpath "$xpath" $xml
}
echo "homeCommunity info:"
echo "-----------------------------"
echo -e
xpath "//*[local-name()='property'][@name='homeCommunityId']/*[local-name()='value']/text()" $out_file
echo -e
echo -e
echo "registry info:"
echo "-----------------------------"
echo -e
xpath "//*[local-name()='property'][@name='regUniqueId']/*[local-name()='value']/text()" $out_file
echo -e
echo -e
echo "repositoryUniqueId entries:"
echo "-----------------------------"
echo -e
xpath "string(//*[local-name()='map'][@id='connectionBeanProperties']/*[local-name()='entry'][@key='repositoryUniqueId']/@value)" $out_file
echo -e
xpath "(//*[local-name()='property'][@name='repUniqueId']/*[local-name()='value']/text())[1]" $out_file
echo -e
xpath "(//*[local-name()='property'][@name='repUniqueId']/*[local-name()='value']/text())[2]" $out_file
echo -e
echo -e
echo "urlRepository entries:"
echo "-----------------------------"
echo -e
xpath "string(//*[local-name()='map'][@id='connectionBeanProperties']/*[local-name()='entry'][@key='urlRepository']/@value)" $out_file
echo -e
echo -e
echo "urlRegistry entries:"
echo "-----------------------------"
echo -e
xpath "string(//*[local-name()='map'][@id='connectionBeanProperties']/*[local-name()='entry'][@key='urlRegistry']/@value)" $out_file
echo -e
echo -e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment