Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. key1 = This is 1st value
  2.  
  3. key2 = this is 2nd value
  4.  
  5. key3
  6.  
  7. #!/bin/bash
  8.  
  9. # Read configuration into an associative array
  10. declare -A CONFIG
  11. # IFS is the 'internal field separator'. In this case, your file uses '='
  12. IFS="="
  13. while read -r key value
  14. do
  15. if [ -n $value ]; then
  16. CONFIG[$key]=$value
  17. else
  18. CONFIG[$key]=$value
  19. fi
  20. done < YOUR_CONFIG_FILENAME
  21. unset IFS
  22.  
  23. # If a parameter is passed, look it up by that, else print everything.
  24. if [ $1 ]; then
  25. if [ -n ${CONFIG[$1]} ]; then
  26. echo "Key: $1, Value: ${CONFIG[$1]}"
  27. else
  28. echo "The key '$1' does not exist"
  29. fi
  30. else
  31. for key in "${!CONFIG[@]}"; do
  32. if [ -n ${CONFIG[$key]} ]; then
  33. echo "Key: $key, Value: ${CONFIG[$key]}"
  34. else
  35. echo "Key: $key has no value"
  36. fi
  37. done
  38. fi
  39.  
  40. exit $?
  41.  
  42. #!/bin/bash
  43. PROPERTY_FILE=filename.properties
  44.  
  45. function getProperty {
  46. PROP_KEY=$1
  47. PROP_VALUE=`cat $PROPERTY_FILE | grep "$PROP_KEY" | cut -d'=' -f2`
  48. echo $PROP_VALUE
  49. }
  50.  
  51. echo "# Reading property from $PROPERTY_FILE"
  52. DB_USER=$(getProperty "db.username")
  53. DB_PASS=$(getProperty "db.password")
  54. ROOT_LOC=$(getProperty "root.location")
  55. echo $DB_USER
  56. echo $DB_PASS
  57. echo $ROOT_LOC
  58. echo "Writing on DB ... "
  59. mysql -u$DB_USER -p$DB_PASS dbname<<EOFMYSQL
  60.  
  61. update preference set tablename.value_ = "$ROOT_LOC" where tablename.name_="Root directory location";
  62. EOFMYSQL
  63. echo "Writing root location($ROOT_LOC) is done ... "
  64. 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"`;
  65.  
  66. if [ "$counter" = "1" ]
  67. then
  68. echo "ROOT location updated"
  69. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement