Re: pg_dump command inside shell scripts

From: Roj Niyogi <niyogi(at)pghoster(dot)com>
To: Elielson Fontanezi <ElielsonF(at)prodam(dot)sp(dot)gov(dot)br>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: pg_dump command inside shell scripts
Date: 2002-10-08 19:03:31
Message-ID: 3DA32C03.9000009@pghoster.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin 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(at)pghoster(dot)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(at)postgresql(dot)org so that your
>message can get through to the mailing list cleanly
>
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Chris Miles 2002-10-08 20:57:16 Re: PostgreSQL and 2-node failover cluster solutions
Previous Message Josh Goldberg 2002-10-08 18:52:11 Re: problems with pltcl.so

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2002-10-08 19:55:51 Re: Returning composite types from functions
Previous Message Doug Fields 2002-10-08 18:06:47 ORDER BY and LIMIT questions in EXCEPTs