On 14/03/14 17:28, kreczko wrote:
>>       # needs check if already exists, otherwise will wipe the tables!
>>       onlyif  =>  [
>> -      '/usr/bin/test `/usr/bin/mysql --defaults-file=/root/.my.cnf -e "use apelclient; show tables;SELECT FOUND_ROWS();" 2>&1 | cut -f1 | egrep "^(0|[1-9][0-9]*)$"` -eq 0',
>> -      '/usr/bin/test -f /usr/share/apel/client.sql'],
>> +      # only run if the database exists and does not contain any tables (found rows == 0), don't run in all other cases
>> +      "/usr/bin/mysql --defaults-file=/root/.my.cnf -BNe 'show tables; SELECT FOUND_ROWS();' ${mysql_database} | /bin/grep '^0$'",
>
> Thank you for the clarification.
>

I've another comment on your initial test, which you should be aware 
off. It doesn't matter in this case, but under other circumstances it's 
the "/usr/bin/test `...` -eq 0" that's dangerous. In your original test, 
if the mysql command fails (for whatever reasons), `...` won't produce 
any output. so the test would be "/usr/bin/test -eq 0" which is invalid 
because -eq is missing a parameter. This evaluates to false which 
wouldn't cause any problems in this case because it's still false, but 
could cause serious problems if the condition would be inverted (unless 
=> "/usr/bin/test `...` -ne 0") . If you compare the output of other 
scripts or commands, avoid numerical comparison (-eq, -ne), use string 
comparison (= or !=) instead and always test for empty strings. Safer 
versions of your original test would be either.
'/usr/bin/test "`...`" = "0"' or
'/usr/bin/test x`...` = x0'