Need expect to read variables from a list while logged into the same device

Hi,

I'm primarily a Cisco/Juniper networking guy, so you'll have to forgive my ignorance when it comes to scripting (although I do write simple backup scripts and things of that nature on a regular basis and I run Linux at home, so I am vaguely familiar with it). What I need to do should be fairly simple, but I can't find much on how to do it (either that or I need to get better at describing my problem when searching). I have seen tons of tutorials on the Internet on how to have expect loop through a list of IP addresses for different devices, logging in and issuing commands in each device along the way. However, what I need to do is issue repetitive commands for different variables in the same device over and over again until finished. (We have an issue wherein we have to delete 100 or so customer configurations out of a device, clear their associated circuit and handle identifiers, and then rebuild them to get them working again). I have most of what I need, I just need to figure out how to integrate the list into the script itself.

#!/opt/csw/bin/expect

set device [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]
set pvc ????????
set circuit ????????
set handle ?????????

spawn telnet $device

expect "sername:"
send "$user\r"
expect "assword:"
send "$pass\r"
expect ">"
send "en\r"
expect "assword:"
send "$pass\r"
expect "#"
send "config\r"
expect onfig)#"
send "port eth 10/1\r"

####Here is the part that needs to loop over and over ####until the list of PVCs is complete.

expect "port)#"
send "dot1q pvc $pvc\r"
expect "pvc)#"
send "no bind\r"
expect "pvc)#"
send "exit\r"
expect "port)#"
send "no dot1q pvc $pvc\r"

####Then it resumes normal operation

expect "port)#"
send "end\r"

####and loops through a different list

expect "#"
send "clear ism circuit $circuit\r"
expect "#"

####and loops through a third one

expect "#"
send "clear ism handle $handle\r"
expect "#"

I'm pretty sure the "pvc" "circuit" and "handle" parts are wrong and I have to do some sort of "do while" counter thing, but again, I'm still sort of learning this stuff.

Here's an example list for the type of input that $pvc would have:

936:21
936:25
936:28
941:22

Thanks in advance for the help!

Use a listing script to drive a editing script, like sed, to dynamically make the expect script with the list of commands you need.

For a list try something like this:

set pvc_list [list 936:21 936:25 936:28 941:22 ]
 
foreach pvc $pvc_list {
    expect "port)#"
    send "dot1q pvc $pvc\r"
    expect "pvc)#"
    send "no bind\r"
    expect "pvc)#"
    send "exit\r"
    expect "port)#"
    send "no dot1q pvc $pvc\r"
}