I have a shell script thats generated by a java jar that I am unable to run anything postgres related when its created. However, when copying all of its content into a new shell script file, I am able to run the script flawlessly. The content of the script is basically just connecting to my postgres database, creating a new database and populating it. Here's a snippet:
#!/bin/bash export DATABASE_NAME="dbname" export DB_USERNAME="postgres" psql -c "drop database $DATABASE_NAME;" postgres postgres psql -c "create database $DATABASE_NAME;" postgres postgres echo "Starting scripts" psql -f db/pgsql/schema/schema.sql $DATABASE_NAME $DB_USERNAME
Any ideas on why this is the case?
EDIT: For clarification, the script errors when it reaches this line:
psql -c "drop database $DATABASE_NAME;" postgres postgres
It is giving the following error for every line that needs to be executed in this file:
psql: fe_sendauth: no password supplied
Things I've confirmed:
Shell script is executable
~/.pgpass has the necessary credentials
If copying contents of this script to a new file and I run that file, everything runs as expected.