pxssh 如何发送线路 'N' 以提示 "[Y/N]"
pxssh how to sendline 'N' to prompt "[Y/N]"
我想使用 pxssh 为 NetScaler 制作一个自动升级脚本——一个基于 FreeBSD 的产品。
我在 FreeBSD 上成功上传和 tar 固件并安装它。
使用 promop "Do you want to enable it NOW? [Y/N]" 时,我的脚本无法向它发送行 "No"
错误代码是“'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
,或者两次都分配给它,而不是分配一次并调用另一个。
我想使用 pxssh 为 NetScaler 制作一个自动升级脚本——一个基于 FreeBSD 的产品。
我在 FreeBSD 上成功上传和 tar 固件并安装它。
使用 promop "Do you want to enable it NOW? [Y/N]" 时,我的脚本无法向它发送行 "No"
错误代码是“'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
,或者两次都分配给它,而不是分配一次并调用另一个。