0

I'm trying to make this work

#!/usr/bin/expect spawn "(psql blabla \"blabla sql;\" &> /dev/null) && (pg_restore -d xx my_file.sql &> /dev/null)" expect "Password for user my_base: " send "v" 

But I always get:

spawn (psql blabla "blabla sql;" &> /dev/null) && (pg_restore -d xx my_file.sql &> /dev/null) couldn't execute "(psql blabla "blabla sql;" &> /dev/null) && (pg_restore -d xx my_file.sql &> /dev/null)": no such file or directory 

What am I missing?

2 Answers 2

1

1) don't put the spawn arguments in quotes, and 2) spawn doesn't understand shell syntax, you need to explicitly spawn a shell

spawn bash -c {(psql blabla "blabla sql;" &> /dev/null) && (pg_restore -d xx my_file.sql &> /dev/null)} 

This uses braces, which are the expect/Tcl equivalent of shell's single quotes.

2
  • Thanks a lot it works. I have to learn: C#, JavaScript, HTML, CSS, Python, Django, docker, kubernetes, not to talk about git and all this "months learning curve", and now shell............................ so I feel "a bit" overwhelmed.... Commented Jan 17, 2020 at 18:08
  • not to mention expect which does have a fairly steep learning curve. Commented Jan 17, 2020 at 18:30
0

Although this is not really the answer to your question, but if you're trying to do a pg_restore without entering a password, you can also use the ~/.pgpass file to store credentials in.

Postgres documentation on ~/.pgpass -

https://www.postgresql.org/docs/current/libpq-pgpass.html

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.