简体   繁体   English

pxssh如何发送“ N”行以提示“ [Y / N]”

[英]pxssh how to sendline 'N' to prompt “[Y/N]”

I want to use pxssh to make a auto-upgrade script for NetScaler---a FreeBSD based product. 我想使用pxssh为NetScaler(基于FreeBSD的产品)制作自动升级脚本。

I successfully upload and tar firmware on FreeBSD and install it. 我成功地在FreeBSD上上传了tar固件并将其安装。

With promop "Do you want to enable it NOW? [Y/N]" , my script failed to sendline "No" to it 使用promop“是否要立即启用它吗?[是/否]”,我的脚本无法向其发送“否”行

Error Code is "'str' object is not callable" 错误代码为“'str'对象不可调用”

Below is output: 输出如下:

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]# 

Below is my script 下面是我的脚本

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)

I don't know your library at all, but I'd guess the issue is the conflict between these two lines: 我根本不了解您的库,但是我想问题是这两行之间的冲突:

ssh_command.PROMPT='Do you want to enable it NOW? [Y/N]'
...
ssh_command.PROMPT('Reboot NOW? [Y/N]')

I'm not sure which is correct, but probably you want to either be calling PROMPT both time, or assigning to it both times, not assigning once and calling the other. 我不确定哪个是正确的,但是您可能想两次都调用PROMPT ,或者两次都分配给PROMPT ,而不是一次分配就调用另一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM