Results 1 to 8 of 8
I have a simple bash script to automate database creation for a new development branch.
It is run using ./branch-db from to
Code:
mysqldump -u root -pPASSWORD_IS_HERE $1 > $2.sql
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-15-2012 #1
Bash script parameter substitution
I have a simple bash script to automate database creation for a new development branch.
It is run using ./branch-db from to
works fine butCode:mysqldump -u root -pPASSWORD_IS_HERE $1 > $2.sql
simply creates a schema called $2 instead of being called to in the example. I have also triedCode:mysql -u root -pPASSWORD_IS_HERE -e 'create schema $2'
but that gives a syntax error.Code:mysql -u root -pPASSWORD_IS_HERE -e 'create schema ${2}'
How do I get the $2 to substitute correctly?If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
The Fifth Continent reborn
- 06-15-2012 #2
Use doublequotes instead of single.
Doublequotes allow variable evaluation.
Depending on what and how much you want to pass, the quoting and escaping can be a nightmare.Code:mysql -u root -pPASSWORD_IS_HERE -e "create schema $2"
It might be a better approach to write a file with all the sql code and just do:
P.S. The pw on the commandline is a big NoNo, as it will show in the processlist.Code:mysql -u root -pPASSWORD_IS_HERE < initialize.sql
You can use an option file instead.You must always face the curtain with a bow.
- 06-15-2012 #3
Double quotes like PHP. I didn't even thing of that even after all my years with PHP

It's a dev box with no access to the outside workd and no important data so the command line password isn't a problem. It also shows the password in the mysql history - and that's in plain text
Passing only alphanumeric and underscores so escaping shouldn't be an issue I would hope?If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
The Fifth Continent reborn
- 06-15-2012 #4
Alphanumeric and underscores are not a problem.
<preacher mode>
Is it an option for you to invest time and thought into a systemmanagement tool like puppet or chef?
A mysql server manifest can: install all needed packages (even cross platform), config the daemon according to env, host or even dynamically accordding to e.g. ram or number of cores, initialize databases, take care of db dump crons, configure logging, etc
In short: it offers repeatability and consistency
I even use it for my private machines and vms.
Deploy a new one, install puppet, copy my private key and a (very hackish) manifest to the box.
and the new workstation has all my usual tools, configured correctly.Code:puppet apply hackish_manifest
</preacher mode>You must always face the curtain with a bow.
- 06-15-2012 #5
Not for me - I'm a humble developer who only gets to play on the dev server occasionally as needed. It may be worth mentioning to the guys who look after the live boxes but I suspect they will have something like that in place anyway.
[edit]If I get time I may look into it at home. More knowledge is more knowledge after all[/edit]If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
The Fifth Continent reborn
- 06-15-2012 #6
There is this tutorial:
Learning Puppet ? Documentation ? Puppet Labs
It can be done in half a day (max) and it will give you a first impression and overview.
Especially as a dev you might find it appealing, as it is not scripting any more but programmatically designing and maintaining a dev/work/production environment.You must always face the curtain with a bow.
- 06-16-2012 #7
This is just wonderful to observe, two major contributors having this conversation without hubris.
- 06-16-2012 #8If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
The Fifth Continent reborn


Reply With Quote

