繁体   English   中英

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

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

我想使用pxssh为NetScaler(基于FreeBSD的产品)制作自动升级脚本。

我成功地在FreeBSD上上传了tar固件并将其安装。

使用promop“是否要立即启用它吗?[是/否]”,我的脚本无法向其发送“否”行

错误代码为“'str'对象不可调用”

输出如下:

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)

我根本不了解您的库,但是我想问题是这两行之间的冲突:

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

我不确定哪个是正确的,但是您可能想两次都调用PROMPT ,或者两次都分配给PROMPT ,而不是一次分配就调用另一个。

暂无
暂无

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

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