Thread: Batch authentication with psql -- SOLVED

Batch authentication with psql -- SOLVED

From
"David F. Skoll"
Date:
Hi,

I needed a way to supply a password to psql from shell scripts and
cron jobs, but didn't want to install "expect" -- too complex.

I wrote a simple little C program called "notty" which convinces psql
that it has no controlliny TTY, and then it reads the password from
stdin.

So instead of:

    psql [options] < commands.sql

You use:

    (echo "password"; cat commands.sql) | notty psql [options]

The C source code is at http://www.roaringpenguin.com/notty.c.txt

It is verified to work on Linux and Solaris, and should work on any
modern UNIX.  On any decent UNIX system, you should be able to save
the file as "notty.c" and type:

    make notty

to build it.

Regards,

David.