When administering network devices such as the Cisco Catalyst 3850, performing password changes securely and efficiently is crucial to maintaining network security. The following template provides an example of how you might structure a script using expect to perform a password change on the Cisco Catalyst 3850.
Detailed Description of Password Change Template:
set-connect-timeout 15
set-read-timeout 15
#
expect "*#"
exec "conf t"
#
expect "*(config)#"
exec "username [#USERNAME#] privilege 15 secret [#NEW_PASSWORD#]"
#
no-expect "*%*"
exec " "
#
expect "*(config)#"
exec "do wr"
#
expect "*(config)#"
exec "do show runn | i [#USERNAME#]"
#
expect "*(config)#"
exec "exit"
#
expect "*#"
exec "exit"