我正在尝试使用 keepassdb 自动化 ssh 连接,并且我刚刚开始编写脚本来询问 keypass kpcli shell。我希望它在最后打印出结果。
# -*- 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)
尝试运行文件时收到以下信息:
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