Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- key1 = This is 1st value
- key2 = this is 2nd value
- key3
- #!/bin/bash
- # Read configuration into an associative array
- declare -A CONFIG
- # IFS is the 'internal field separator'. In this case, your file uses '='
- IFS="="
- while read -r key value
- do
- if [ -n $value ]; then
- CONFIG[$key]=$value
- else
- CONFIG[$key]=$value
- fi
- done < YOUR_CONFIG_FILENAME
- unset IFS
- # If a parameter is passed, look it up by that, else print everything.
- if [ $1 ]; then
- if [ -n ${CONFIG[$1]} ]; then
- echo "Key: $1, Value: ${CONFIG[$1]}"
- else
- echo "The key '$1' does not exist"
- fi
- else
- for key in "${!CONFIG[@]}"; do
- if [ -n ${CONFIG[$key]} ]; then
- echo "Key: $key, Value: ${CONFIG[$key]}"
- else
- echo "Key: $key has no value"
- fi
- done
- fi
- exit $?
- #!/bin/bash
- PROPERTY_FILE=filename.properties
- function getProperty {
- PROP_KEY=$1
- PROP_VALUE=`cat $PROPERTY_FILE | grep "$PROP_KEY" | cut -d'=' -f2`
- echo $PROP_VALUE
- }
- echo "# Reading property from $PROPERTY_FILE"
- DB_USER=$(getProperty "db.username")
- DB_PASS=$(getProperty "db.password")
- ROOT_LOC=$(getProperty "root.location")
- echo $DB_USER
- echo $DB_PASS
- echo $ROOT_LOC
- echo "Writing on DB ... "
- mysql -u$DB_USER -p$DB_PASS dbname<<EOFMYSQL
- update preference set tablename.value_ = "$ROOT_LOC" where tablename.name_="Root directory location";
- EOFMYSQL
- echo "Writing root location($ROOT_LOC) is done ... "
- counter=`mysql -u${DB_USER} -p${DB_PASS} dbname -e "select count(*) from tablename where tablename.name_='Root directory location' and tablename.value_ = '$ROOT_LOC';" | grep -v "count"`;
- if [ "$counter" = "1" ]
- then
- echo "ROOT location updated"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement