-1

I am trying to automate ssh connectivity using keepassdb and I am just starting out the script to interrogate the keypass kpcli shell. I want it to print out the result at the end.

# -*- coding: utf -*-
import os,sys
import pexpect
global str
db_kp='/media/sf_VM_shared/passwords.kdb'
pass_kp='KDBPASSWORD'
kp = pexpect.spawn('/usr/bin/kpcli')
kp.expect('>')
kp.sendline=('open /media/sf_VM_shared/passwords.kdb')
kp.expect=('Please provide the master password:')
kp.sendline=(pass_kp)
kp.expect('>')
kp.sendline=('cd General/Network/Firewalls/SSH/')
kp.expect=('kpcli:/General/Network/Firewalls/SSH>')
kp.sendline=("show -f 0")
print(kp.before)

I am getting the following when trying to run the file:

python3 ssh_firewall.py 
Traceback (most recent call last):
File "ssh_firewall.py", line 12, in <module>
kp.expect('>')
TypeError: 'str' object is not callable
Paul Dawson
  • 1,332
  • 14
  • 27

1 Answers1

0

On this line:

kp.expect=('Please provide the master password:')

You're replacing the expect function, rather than calling it. Take the = out:

kp.expect('Please provide the master password:')

You're doing the same thing with kp.sendline, so you'll need to fix that as well.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
  • Thanks! I get a bit further now. It looks like it gets to the cd command and then drops me out but doesn't print what is in the kpdb file: pdvb@pdvb:~$ python3 -d ssh_firewall.py b':/> cd General/Network/Firewalls/' – Paul Dawson Nov 25 '15 at 11:23
  • I'm now getting b':/' Is there a way to debug? – Paul Dawson Nov 25 '15 at 11:32
  • I've managed to do this and print the output to a buffer but I am getting unreliable results when using this data, probably because it's in a buffer and unformatted. child.sendline('open /media/sf_VM_shared/Paul.kdb') child.expect('Please provide the master password:') child.sendline(pass_child) child.expect('>') child.sendline('cd General/Network/Firewalls/SSH') child.expect('SSH') child.sendline("show -f 0") child.expect('Path') print(child.buffer) – Paul Dawson Nov 25 '15 at 14:04