1

The hibernate.cfg contains database configuration such as username,password,dbname and dbhost

    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://DBHOST:3306/DBNAME?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;tcpKeepAlive=true</property>
    <property name="connection.username">DBUSER</property>
    <property name="connection.password">DBPASS</property>

I need a bash script to extract these data.

MKT
  • 655
  • 1
  • 6
  • 18

1 Answers1

2

Using xmlstarlet, you can use xpath.

$ xmlstarlet sel -t -v './/property[starts-with(@name, "connection.")]' hiberate.cfg 2>/dev/null ; echo
com.mysql.jdbc.Driver
jdbc:mysql://DBHOST:3306/DBNAME?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;tcpKeepAlive=true
DBUSER
DBPASS
$
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • +1 How refreshing. Not yet another link to [this classic](http://stackoverflow.com/a/1732454/383793), but a CLI tool I didn't know. – Chris Wesseling Mar 29 '14 at 10:49