Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Nevermind.

I had a 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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.