Hello I'm using a unix command to execute an postgres psql script, which creates a DB, in theory it could be more complex, after this command i am using ">>" to save the output on a file, the thing is it only save when the database succeeded on creation but when it fails because it already exists doesn't store anything.
Here's an example of the full command
sudo -u postgres psql -f /home/user/script.sql >> /home/user/output.txt
in the script i just have "create database db2;"
I'm Using Ubuntu 14.04 and Postgres 9.3.4
Any hint or help would be great. Or if any information needed i will gladly answer you.