Simple "expect" script to log in and issue CLI commands to a cisco router only lasts two expects long
<p>this is my script"</p>

<pre><code>#!/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"
</code></pre>

<p>Basically I want the script to ssh, avoid cert checks, log in, make the router go in config mode, then go to vlan 250 config mode and finally rename the vlan. What is happening is that the script reaches the config-vlan mode but immediately exits the script before issuing that last command. No matter what I do it never throws that last command. The last "expect" check is properly configured.</p>

<pre><code>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:/#
</code></pre>