Use the exit status and test() for it. if the database exists, then you'll exit with status 0, if not, you'll exit with non-zero.
Lee Hambley -- http://lee.hambley.name/ +49 (0) 170 298 5667 On 4 April 2014 21:21, Vell <lovell.mcilw...@gmail.com> wrote: > Versions: > > - Ruby 2.0 > - Capistrano 3.1 > - Rake / Rails / etc 4.0.4 > > Platform: > > - Working on.... mac os x > - Deploying to... centos 6.5 > > Logs: > > - Please past logs (as completely as possible to a 3rd party pasting > service such as pastie.org) > > Files: > > - Capfile > - deploy.rb > - Stage files (production.rb, staging.rb) > > Hello all, > > I am attempting to make it so that capistrano creates a db if it doesn't > exist. Right now I am able to run the command to check for the db but I am > not able to capture the "unknown database" message that comes out from > MYSQL. > > I'm sure there is a way to do it, I just haven't figured it out the right > way to do it. The code I am starting with is below: > > desc "check if db exists on remote server. If not create it." > task :check_db do > on roles(:app) do |host| > puts "-"*100 > puts capture("mysql -usomeuser -psomepassword > #{fetch(:application)}_#{fetch(:rails_env)}") > end > end > > I have also tried: > > puts %x("mysql -usomeuser -psomepassword > #{fetch(:application)}_#{fetch(:rails_env)}") > > The response I get is: > > DEBUG [242e1da5] Command: mysql -usomeuser -psomepassword > app_name_dev_server > DEBUG [242e1da5] ERROR > DEBUG [242e1da5] 1049 (42000) > DEBUG [242e1da5] : Unknown database 'online_community_dev_server' > > > That last line, or even the one before it, I can't seem to catch it to use > in a condition statement. > > > Any thoughts would be greatly appreciated. > > -- > You received this message because you are subscribed to the Google Groups > "Capistrano" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to capistrano+unsubscr...@googlegroups.com. > To view this discussion on the web, visit > https://groups.google.com/d/msgid/capistrano/e75b0b3e-6bda-4ea6-961a-55e50eb5fe86%40googlegroups.com<https://groups.google.com/d/msgid/capistrano/e75b0b3e-6bda-4ea6-961a-55e50eb5fe86%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Capistrano" group. To unsubscribe from this group and stop receiving emails from it, send an email to capistrano+unsubscr...@googlegroups.com. To view this discussion on the web, visit https://groups.google.com/d/msgid/capistrano/CAN_%2BVLWdo-RpCGveOBDah_ZXjS0DvTCGtXeaJMCF_Lbz%3Do14aw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.