这是我的脚本“
#!/usr/bin/expect -f
set USERNAME "user"
set PASSWORD "password"
set ENABLEPSW "enable-password"
set HOST "host-fqdn"
spawn ssh -o StrictHostKeyChecking=no $USERNAME@$host-fqdn
expect "Password: "
send "$PASSWORD\n"
expect "*# "
send "config t\n"
expect "*(config)# "
send "vlan 250\n"
expect "(config-vlan)# "
send "name NEWNAME\n"基本上,我希望脚本为ssh,避免证书检查,登录,使路由器进入配置模式,然后进入VLAN250配置模式,最后重命名vlan。实际情况是,脚本进入config-vlan模式,但在发出最后一条命令之前立即退出脚本。无论我做什么,它都不会抛出最后一个命令。最后一个"expect“检查配置正确。
root@shell:/# ./routerconnect.sh
spawn ssh -o StrictHostKeyChecking=no USERNAME@HOST-FQDN
User Access Verification
Password:
Cisco Nexus Operating System (NX-OS) Software
TAC support: http://www.cisco.com/tac
Copyright (C) 2002-2015, Cisco and/or its affiliates.
All rights reserved.
The copyrights to certain works contained in this software are
owned by other third parties and used and distributed under their own
licenses, such as open source. This software is provided "as is," and unless
otherwise stated, there is no warranty, express or implied, including but not
limited to warranties of merchantability and fitness for a particular purpose.
Certain components of this software are licensed under
the GNU General Public License (GPL) version 2.0 or
GNU General Public License (GPL) version 3.0 or the GNU
Lesser General Public License (LGPL) Version 2.1 or
Lesser General Public License (LGPL) Version 2.0.
ROUTER# config t
Enter configuration commands, one per line. End with CNTL/Z.
ROUTER(config)# interface vlan 250
ROUTER(config-vlan)#
root@shell:/#发布于 2016-11-19 21:36:52
您需要等待name命令完成。所以试着这样做:
send "name NEWNAME\n"
# The last command finishes only when you see the next prompt.
expect "(config-vlan)# "https://stackoverflow.com/questions/40686311
复制相似问题