# How to use expect to automatically use fdbcli unlock db?

**URL:** <https://forums.foundationdb.org/t/how-to-use-expect-to-automatically-use-fdbcli-unlock-db/3305>\
**Category:** Using FoundationDB\
**Created:** [May 9, 2022, 1:16am UTC](https://forums.foundationdb.org/t/how-to-use-expect-to-automatically-use-fdbcli-unlock-db/3305 "2022-05-09T01:16:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![liuyan](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@liuyan](https://forums.foundationdb.org/u/liuyan)\
**Post date:** [May 9, 2022, 1:16am UTC](https://forums.foundationdb.org/t/how-to-use-expect-to-automatically-use-fdbcli-unlock-db/3305/1 "2022-05-09T01:16:52Z")

</div>

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:

```auto
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:

```auto
Unlocking the database is a potentially dangerous operation.
true

```

kindly share any advise how to capture passphase. thanks.

---

<div class="post-metadata">

**Author:** ![liuyan](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@liuyan](https://forums.foundationdb.org/u/liuyan)\
**Post date:** [May 9, 2022, 8:58am UTC](https://forums.foundationdb.org/t/how-to-use-expect-to-automatically-use-fdbcli-unlock-db/3305/2 "2022-05-09T08:58:56Z")

</div>

@ **[tclinken](https://github.com/tclinken)** do you have any suggestions on how to proceed? thankl you.

---

<div class="post-metadata">

**Author:** ![markus.pilman](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/markus.pilman/32/379_2.png) [@markus.pilman](https://forums.foundationdb.org/u/markus.pilman)\
**Post date:** [May 9, 2022, 12:47pm UTC](https://forums.foundationdb.org/t/how-to-use-expect-to-automatically-use-fdbcli-unlock-db/3305/3 "2022-05-09T12:47:49Z")

</div>

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](https://github.com/apple/foundationdb/blob/3bf53575629a4537ae157d95de4106b27ea9c28a/fdbclient/ManagementAPI.actor.cpp#L2068) to see what you need to run.
