Reputation: 2110
I'm trying to clone a db with exec from mysql, but I don't want to clone it if it has already been cloned.
exec { "clone_from_${name}" :
unless => "/usr/bin/mysql -u${user_to} -p${pwd_to} ${name_to} -e'select count(*) from $test_table_name;' | grep -c ' 0 '",
...
The logic looks a little confusing but basically, the way I understand unless is that if the command returns a 0, then the whole exec wont be run. But it when I try it, it is.
The db has already been created in the vm, and if it's already been cloned, the count returned from the query gives me something other than a ' 0 ', and the grep because it doesn't find the ' 0 ' returns a 0. Unless should make it run then, right?
The output even gives me "Unless: 0" and then "Executing
Thanks.
Upvotes: 1
Views: 3566
Reputation: 1232
It's the exitcode that is important, not the number that is printed.
If you run this command manually and do an echo $?
afterwards, you get the exitcode.
Also, you want to surpress the output from the command:
exec { "clone_from_${name}" :
unless => "/usr/bin/mysql -u${user_to} -p${pwd_to} ${name_to} -e'select count(*) from $test_table_name;' | grep ' 0 ' > /dev/null 2>&1",
...
Upvotes: 4