Runing this command:

sshpass -p "pass" ssh [email protected] "pg_dump -U foo some_db"

runs perfectly fine. It returns on stdandard output the dump of db.

Then I would like to restore new_db based on dump redirected to stdin

 psql -U foo -d new_db < `sshpass  -p "pass" ssh  [email protected] "pg_dump -U foo some_db"`

I got error: ambiguous redirect

1 Answer 1


I suggest this :

sshpass  -p "pass" ssh  [email protected] "pg_dump -U foo some_db" | psql -U foo -d new_db

This will pipe ssh standard output into psql standard input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.