priyank
priyank

Reputation: 4724

postgres password less connection not working from shell script

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.

Upvotes: 2

Views: 518

Answers (1)

priyank
priyank

Reputation: 4724

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

Upvotes: 2

Related Questions