How to use regexp with linux expect?

65 views Asked by At

I want to use Duplicity to backup my files from shell, but it requires the password to be passed twice before run. I thought of expect to solve the problem, but I cannot make it work. What I tried:

expect "Local and Remote metadata are synchronized, no sync needed.\nLast full backup date: none\nLast full backup is too old, forcing full backup\nGnuPG passphrase for decryption: " {send "$pass\r"}
expect "Retype passphrase for decryption to confirm: " {send "$pass\r"}

There is a multi line message from Duplicity. I tried expect -re to use regexp, but it did not recognize the r option. I use Alpine in a docker container.

1

There are 1 answers

0
glenn jackman On BEST ANSWER

The first pattern is not matching because Expect uses \r\n for all newlines.

Run your code with expect -f script.exp for verbose output to see how expect is attempting to match.

You could write

expect "Local and Remote metadata*GnuPG passphrase for decryption: " {send "$pass\r"}

By default, the expect command uses glob-matching like the tcl string match commabnd