How to use expect to automatically use fdbcli unlock db?

I am trying to automatically unlock db using follow command:
fdbcli --exec "unlock e37047b3d0c2860b235d684a5a29baac"
the output is like
Unlocking the database is a potentially dangerous operation.
Repeat the following passphrase if you would like to proceed (3USlDAq5EF) :
we need to capture the passphrase and input it back, how to do that?
I tried to use go expect, but it sounds it only capture the first line of the output, meaning couldn’t get the passphrase. I also attach a simple go code:

package main

import (
        "fmt"

        gexpect "github.com/ThomasRooney/gexpect"
)

func main() {

        child, err := gexpect.Spawn("fdbcli --exec \"unlock e37047b3d0c2860b235d684a5a29baac\"")

        if err != nil {
                panic(err)
        }
        _, receiver := child.AsyncInteractChannels()
        line1, open := <-receiver
        fmt.Println(line1)
        fmt.Println(open)

        child.Expect("):")
        child.SendLine("passphase")
        child.Interact()
        child.Close()
}

the output is:

Unlocking the database is a potentially dangerous operation.
true

kindly share any advise how to capture passphase. thanks.

@ tclinken do you have any suggestions on how to proceed? thankl you.

You could use some python script that modifies the system keyspace. But be sure to test it properly as modifying the system keyspace can result in data corruption or complete data loss. You can look at the FDB implementation to see what you need to run.

1 Like