Home > Software design >  I cannot pass correclty password or I am wrong in this script
I cannot pass correclty password or I am wrong in this script

Time:10-17

I try to mount a borgfs into a directory. However, this command requests a password, so, I have to send a password to stdin. I found in Python this library. However, I cannot mount this fs. Where am I wrong?

./get.py 
<pexpect.pty_spawn.spawn object at 0x7f26997c5100>
command: /usr/bin/borgfs
args: ['/usr/bin/borgfs', '/home/sincorchetes/work/esmerald', '/mnt/work/esmerald']
buffer (last 100 chars): b' for key /home/sincorchetes/work/esmerald: '
before (last 100 chars): ''
after: b'Enter passphrase'
match: <re.Match object; span=(0, 16), match=b'Enter passphrase'>
match_index: 0
exitstatus: None
flag_eof: False
pid: 913893
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

This is the code of the script:

#!/mnt/aborg/bin/python
import pexpect

mypassword = "d6v6Q"
child = pexpect.spawn("borgfs /home/sincorchetes/work/esmerald /mnt/work/esmerald")
child.expect("Enter passphrase for key /home/sincorchetes/work/esmerald: ")
child.sendline(mypassword)

CodePudding user response:

I think based on the output the expecting EOF is the problem here. You don't expect EOF on login, you expect a password prompt on login.
For example

$ Enter passphrase for key /home/sincorchetes/work/esmerald: 
                                    You enter password here ^

You enter the password after the colon on the same line and NOT on the next line like this

$ Enter passphrase for key /home/sincorchetes/work/esmerald: 
$ 
  NOT here on the next line

Change your code to

# rest of the code
child.expect('Enter passphrase for key /home/sincorchetes/work/esmerald: ')
# Remove this line child.expect(pexpect.EOF)
child.sendline(mypassword)

CodePudding user response:

I've could see what's happened with child.interact(). I have a previous cache in borg that I cannot mount this directory into push y word.

Now works 100%.

The result of code:

#!/mnt/aborg/bin/python
import pexpect

mypassword = "d6v6Q"
child = pexpect.spawn("borgfs /home/sincorchetes/work/esmerald /mnt/work/esmerald")
child.expect("Enter passphrase for key /home/sincorchetes/work/esmerald: ")
child.sendline(mypassword)
child.interact()

With the rest of the directories works fine (It's not requested [y/N] reply.

  • Related