Automatic data-dumps with passwords

You have password protected your database but would like an automated dump generated from a cron job.

Solution

Wrap pg_dump in an expect script.

Discussion

Basically you set up a command-file which spawns pg_dump with the relevant parameters waits for a prompt and sends the password.

spawn /path/to/pg_dump (options) (database)
expect (prompt)
send (password)
   

Obviously you'll need to make sure this file is only readable by its owner since it will contain a password in cleartext.

The man page for expect is fairly comprehensive and if you don't have the tool on your system it usually comes with tcl/tk packages.