Since NX-OS is unix-like; we have a simple trick for stringed commands. This can be helpful in scripts or other automated activities.
The stringed the commands allows you to group together one single line of commands that are execute one after another.
E.g a typical expect script might have the following;
expect "NXOS2"
send -- "term leng 0\r"
expect ""
send -- "conf t \r"
expect "NXOS(config)#"
send -- "push top ; int eth 1/1 ; load 30 ; int eth 1/2 ; load 30 ; int eth 1/4 ; load 44 ; int eth 1/9 ; load 30 ; int eth 1/19-20 ; load 30 ; pop ; do copy run start\r"
Here's an example from a screenshot;
NOTE: Stringing commands is great when you have a series of commands to execute at one-shot or session.
Here's a sample expect script with cmd stringing in for the CLI
#!/usr/bin/expect
# usage getnxos.exp <user@host> <password>
set timeout 10
spawn ssh [lindex $argv 0]
set pass [lindex $argv 1]
#
expect "word:"
send -- "$pass\r"
expect "SW2#"
send -- "term leng 0 ; show interface status ;\r "
expect "SW2#"
send -- "show inv | inc power ; term leng 0 ; show run int eth1/1 ; show run int eth 1/24 ; show logging last 20 | tr \-d \"SW2\" \r"
expect "SW2#"
send -- "exit\r "
~
~
Ken Felix
NSE ( Network Security Expert) and Route/Switching Engineer.
kfelix -----a----t---- socpuppets ---dot---com
^ ^
=( * * )=
o
/ \
No comments:
Post a Comment