#!/bin/sh path="/usr/share" if [[ -e "$path/tomcat9/conf" ]] then path="$path/tomcat9/conf" elif [[ -e "$path/tomcat8/conf" ]] then path="$path/tomcat8/conf" elif [[ -e "$path/tomcat7/conf" ]] then path="$path/tomcat7/conf" else echo "No tomcat dirs exist / Something went wrong" fi host="$(cat $path/server.xml | grep url= | sed -e 's/url\=\"jdbc\:mysql\:\/\///g' | sed -e 's/\/terminalfour.*//g' | tr -d '[:space:]')" user="$(cat $path/server.xml | grep username= | sed -e 's/username\=\"//g' | sed -e 's/\"//g' | tr -d '[:space:]')" pass="$(cat $path/server.xml | grep password= | sed -e 's/password\=\"//g' | sed -e 's/\"//g' | tr -d '[:space:]')" if [ -n "$1" ]; then mysql -h"$host" -u"$user" -p"$pass" --ssl terminalfour -A -e "$1" else mysql -h"$host" -u"$user" -p"$pass" --ssl terminalfour -A fi