2
votes

I am developing a pre-prod server for Symfony2 app

I made a little hook script to update all of my git repository which containts Symfony app.

#...

# Save old database
DATABASE_NAME=`CMD to Yaml Parser` 'app/config/parameters.yml' database_name
TODAY=`date +"%Y-%m-%d-%H:%M:%S"`
logger -t "Update website Symfony2" "Save SQL in $TODAY.sql"
mysqldump $DATABASE_NAME > sqlSave/$TODAY.sql 2>&1 | logger -t "Update website Symfony2"
# Update database with doctrine
php app/console doctrine:schema:update --force  2>&1 | logger -t "Update website Symfony2"

#...

How can have access to the database name on this script ?

My server is on Debian. Is That a package to parse YAML.

Sorry for my English, I am learning it.

2
Would you be alright with adding a dependency on a scripting language? Many of them have YAML parsing libraries so you could call one of them and have it output the data you want from YAML.Shane Madden

2 Answers

2
votes

Depending on the structure of your app/config/parameters.yml and the location of database_name within it, you might be able to use this parser. It will parse

foo:
  bar:
    key: value
  baz:
    key: value

into bash associative arrays. 100% Bash, but it needs to be Bash 4.x. If you can't stick to Bash 4.x then there are other answers on this question that may help you.

2
votes

You can parse yaml/json file directly in your shell/bash with niet.

Easy to install and easy to use:

$ pip install -U niet

Consider the following example:

$ cat dump.yaml
foo:
  bar:
    key: value
  baz:
    key: value
  tags:
    - one
    - two

You can parse this example file like this:

  $ niet dump.yaml foo.bar.key
  value
  $ for el in $(niet dump.yaml foo.tags); do echo ${el}; done
  one
  two

Niet have a good integration with shell and others bash like.

Niet yaml parser documentation, source code, and samples.