【发布时间】:2018-01-05 21:43:38
【问题描述】:
我想使用 pxssh 为 NetScaler 制作一个自动升级脚本——一个基于 FreeBSD 的产品。
我在 FreeBSD 上成功上传和 tar 固件并安装它。
使用 promop "Do you want to enable it NOW? [Y/N]" ,我的脚本无法发送“否”给它
错误代码是“'str' object is not callable”
下面是输出:
You can also configure this feature anytime using the command line
interface or the configuration utility. Please see the documentation
for further details.
Do you want to enable it NOW? [Y/N]
'str' object is not callable
[root@raynor NS_Auto_Upgrade]#
下面是我的脚本
try:
ssh_command = pxssh.pxssh()
hostname = remotename
username = loginname
password = loginpassword
#ssh_command.PROMPT= '> | Do you want to enable it NOW? [Y/N]' #self-defined original prompt
ssh_command.PROMPT= '> ' #self-defined original prompt
#ssh_command.login(hostname, username, password,original_prompt='[#$>]')
ssh_command.login(hostname, username, password,auto_prompt_reset=False)
ssh_command.prompt()
print(ssh_command.before)
ssh_command.sendline('shell') # run a command
#print(ssh_command.before)
#ssh_command.PROMPT='Do you want to enable it NOW? [Y/N]' # match the prompt
print(f[0:-4])
ssh_command.prompt()
print(ssh_command.before)
ssh_command.sendline('mkdir /var/nsinstall/%s && ls -l /var/nsinstall' % f[0:-4])
ssh_command.prompt()
ssh_command.sendline('tar xzvf /var/nsinstall/%s -C /var/nsinstall/%s' % (f, f[0:-4]))
ssh_command.prompt()
print(ssh_command.before)
ssh_command.sendline('/var/nsinstall/%s/installns' % f[0:-4])
ssh_command.PROMPT='Do you want to enable it NOW? [Y/N]'
ssh_command.prompt()
print(ssh_command.before)
ssh_command.sendline('No')
ssh_command.PROMPT('Reboot NOW? [Y/N]')
ssh_command.prompt()
ssh_command.sendline('Yes')
#ssh_command.prompt()
print(ssh_command.before)
【问题讨论】: