I have a script that does db query in postgres. I'm trying to put in some error checking in the script. I keep running into the password prompt problem where when invalid credentials/or database is put it, it would prompt me for a password which hangs the script. Is there a way that I can check for this kind of failure?
I have pgpass setup so if the crendentials/db/host are correct i will connect perfectly.
for example I have this in my script (with the wrong db), when I run this, it will prompt me for password.
query=`psql -d wrongdatabase -U user -h dbhost -c "select * from whatever;"`
Instead of prompting me for password I would like the script to just exit.