我的食谱中有这个块:
bash "Create admin database tables" do
code "mysql -u root -D admindb < /vagrant/files/admin.sql"
not_if shell_out("mysql -u root -s --skip-column-names -e 'SELECT COUNT(DISTINCT table_name)>0 FROM information_schema.columns WHERE table_schema = \"admindb\";'").stdout().chomp()
end
选择查询的结果是0
或1
写入stdout(仅此而已)。如果查询结果为0
,我只想运行shell命令。我怎样才能实现它?
答案 0 :(得分:2)
您只需要在块内使用Ruby相等运算符。既然你说“只有”输出是0,那么使用only_if
而不是not_if
更简单:
only_if { shell_out("mysql -u root -s --skip-column-names -e 'SELECT COUNT(DISTINCT table_name)>0 FROM information_schema.columns WHERE table_schema = \"admindb\";'").stdout.chomp == '0' }