Problem :
Connecting to postgresql (psql) within a bash script with no password, preferred.
Solution :
- create .pgpass (notice there is a "dot" in front of the filename) in home directory (~/) with permision not more then 0600 (or it will complain)
- the format of the file is
hostname:server-db-port:dbname:username:passworde.g.
192.168.1.10:*:mydatabase:joe:GIjoe or db.domain.com:5432:db01:mike:macha
- in bash script, specify the server details when using psql as specific as possible.
e.g.
DBCONTENTS=$(psql -U mike -h db.domain.com -d db01 -c "select * from mytablename") echo $DBCONTENTS;
AdiĆ³s !!!
No comments:
Post a Comment