I have a shell script (sh) where I create a user and import data to a postgres database <snip> su -c "createuser -A -D -P $PG_user" postgres su -c "psql -d$PG_database -h localhost -U$PG_user -W -f postgresql.sql " postgres </snip> when the script executes those command, it ask for a password, how could I do this without have to enter the passwd, I would like that it reads the password from a variabel, that excists in a separate file, like <variable file> PG_passwd=secret PG_user =username PG_database=simple </variable file> Tronn -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20071030/adab1ffc/attachment-0004.html>
Tronn W?rdahl wrote:> I have a shell script (sh) where I create a user and import data to a > postgres database > > <snip> > su -c "createuser -A -D -P $PG_user" postgres > su -c "psql -d$PG_database -h localhost -U$PG_user -W -f postgresql.sql > " postgres > </snip> >I think, the usage of sudo would solve your problem. Regards Joachim Backes> when the script executes those command, it ask for a password, how could > I do this without have to enter the passwd, I would like that it reads > the password from a variabel, that excists in a separate file, like > > <variable file> > PG_passwd=secret > PG_user =username > PG_database=simple > </variable file> > > > Tronn > > > ------------------------------------------------------------------------ > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos-- Joachim Backes <joachim.backes at rhrk.uni-kl.de> University of Kaiserslautern,Computer Center [RHRK], Systems and Operations, High Performance Computing, D-67653 Kaiserslautern, PO Box 3049, Germany -------------------------------------------------- Phone: +49-631-205-2438, FAX: +49-631-205-3056 http://hlrwm.rhrk.uni-kl.de/home/staff/backes.html -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 6088 bytes Desc: S/MIME Cryptographic Signature URL: <http://lists.centos.org/pipermail/centos/attachments/20071030/048592d0/attachment-0004.bin>
You could set up the User so that no password is required from Localhost if that is appropriate Tronn W?rdahl wrote:> I have a shell script (sh) where I create a user and import data to a > postgres database > > <snip> > su -c "createuser -A -D -P $PG_user" postgres > su -c "psql -d$PG_database -h localhost -U$PG_user -W -f > postgresql.sql " postgres > </snip> > > when the script executes those command, it ask for a password, how > could I do this without have to enter the passwd, I would like that it > reads the password from a variabel, that excists in a separate file, like > > <variable file> > PG_passwd=secret > PG_user =username > PG_database=simple > </variable file> > > > Tronn > ------------------------------------------------------------------------ > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 10/30/07, Tronn W?rdahl wrote:> > PG_passwd=secret > PG_user =username > PG_database=simple >sudo and .pgpass would be better, but for future reference, just source the file in your script. #!/bin/sh source $HOME/.mypgvars Now your PG_* variables have values... - -- Andy Harrison public key: 0x67518262 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: http://firegpg.tuxfamily.org iD8DBQFHJ0tyNTm8fWdRgmIRAmLiAKCJlyYehz0E2Uk7fhbKKTx5pGhRhwCg1tIl CJCiGCD+K014tvvbUXjOp/0=qtJF -----END PGP SIGNATURE-----
On Tue, 2007-10-30 at 12:05 +0100, Tronn W?rdahl wrote:> I have a shell script (sh) where I create a user and import data to a > postgres database > > <snip> > su -c "createuser -A -D -P $PG_user" postgres > su -c "psql -d$PG_database -h localhost -U$PG_user -W -f > postgresql.sql " postgres > </snip> > > when the script executes those command, it ask for a password, how > could I do this without have to enter the passwd, I would like that it > reads the password from a variabel, that excists in a separate file, > like > > <variable file> > PG_passwd=secret > PG_user =username > PG_database=simple > </variable file>---- not at all an answer to your question but what I have found to be useful is to use this in /var/lib/pgsql/data/pg_hba.conf host all all 192.168.1.0/24 pam which means that if the user exists and has his own database in postgres, the user authenticates against the normal auth system (pam) which is set to auth against LDAP which means that I don't have to worry about maintaining an extra password and if I disable the users login, it's disabled everywhere. Craig