2

I have made required entries in .pgpass file with file permission set to 0600.

I am able to connect to db form shell command line without giving the password.

But when I run a shell script which internally queries postgres, it asks to enter password.

I am not able to figure out what could be wrong.

Here is a sample shell script:

#!/bin/bash
source $1
psql -h $DBHOST -d $DBNAME -U $DBUSER << EOF
        select * from students limit 10;
EOF

All values for DBHOST, DBNAME and DBUSER are coming fine.

1 Answer 1

2

Nevermind.

I made a stupid mistake. I had edited config file on windows. So it had added crlf at the end of every line. So even though it was not visible it was being used when connecting to postgres.

So in command line this worked.

psql -h 192.168.1.45 -d somedbname -U $somedbuse

But this did not. (after sourcing config file)

psql -h $DBHOST -d $DBNAME -U $DBUSER
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.