Re: pg_dump command inside shell scripts - Mailing list pgsql-general

From Roj Niyogi
Subject Re: pg_dump command inside shell scripts
Date
Msg-id 3DA32C03.9000009@pghoster.com
Whole thread Raw
In response to pg_dump command inside shell scripts  (Elielson Fontanezi <ElielsonF@prodam.sp.gov.br>)
List pgsql-general
Hi,

Yes, Richard is right about suggesting the expect command.  If you're running a Red Hat-based system, you can download the expect rpm from rpmfind.net.

Once you've installed this, create a file called pg-script.exp and put the following in there:

#!/usr/bin/expect -f

set username [lindex $argv 0]
set password [lindex $argv 1]
set database [lindex $argv 2]

spawn {pg_dump} -u -Ft $database --file=$database.sql.tar
expect "Username:"
send "$username\r"
expect "Password:"
send "$password\r"
expect eof

This will take the username as the 1st argument, password as the second argument and database as the third.  Dumps them into local variables and passes the values when prompted by postgresql.  It "expects" Username: and when comes across that, it sends the value for username along with a carriage return.

Note that it assumes that expect binary is in the /usr/bin directory.

:)

Roj Niyogi
niyogi@pghoster.com

pgHoster - PostgreSQL Web Hosting
http://www.pghoster.com

Richard Huxton wrote:
On Tuesday 08 Oct 2002 2:35 pm, Elielson Fontanezi wrote: 
Hi Folks!
   Again I need a help from you!
   I have develop a shell script (seen below) to do dump and vaccum
automatically.   
 
    But now I need change the $PGDATA/*hba.conf file as it was originally
and
face the password prompt again.   
Do a search on "expect" - probably included with your system and designed for 
this sort of interactive chatting (traditionally with a modem). There's also 
a perl module to do the same.

- Richard Huxton

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly 

pgsql-general by date:

Previous
From: Robert Treat
Date:
Subject: Re: phpPgAdmin + PostgreSQL + authentication
Next
From: Joe Conway
Date:
Subject: Re: Returning composite types from functions