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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need expect to read variables from a list while logged into the same device
# 1  
Old 05-26-2011
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.

Code:
#!/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!

Last edited by wolverene13; 05-26-2011 at 10:22 PM..
# 2  
Old 05-31-2011
Use a listing script to drive a editing script, like sed, to dynamically make the expect script with the list of commands you need.
# 3  
Old 06-01-2011
For a list try something like this:

Code:
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"
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect - bash and variables

I was wondering if anyone could provide some assistance. I trying to run an expect script within bash and get the results of a variable called RESULT. I Have tried a few things but none of them have worked. I know that the child process (the expect script) in this instance cannot set a variable... (6 Replies)
Discussion started by: ylafont
6 Replies

2. Forum Support Area for Unregistered Users & Account Problems

Unable to read threads when logged in

I'm getting the following error (or something similar) whenever I try to view a thread when I'm logged in. That is, I login, hit "New Posts", get a list of theads, click on one (in this example is was the "Not allowed to post URLs" thread), then get the following HTML error page instead of the... (1 Reply)
Discussion started by: cnamejj
1 Replies

3. Shell Programming and Scripting

How to show a list of currently logged in and logging out users?

Hi Guys! I am sure that this question might appeared previously, but I still don't know how to show a list of logged out users. Please help with this! Thanks in advance:) (5 Replies)
Discussion started by: saloliubliu
5 Replies

4. Shell Programming and Scripting

Expect and variables

I'm trying to make an expect function that will pass through a variable. /usr/bin/expect<<EOD spawn su - expect "Password: " send "$psswd\r" expect "#" send "/etc/init.d/network restart >>$log\r" expect "#" send "exit\r" EOD The $log passes through but my $psswd fails I know... (1 Reply)
Discussion started by: Lotheovian
1 Replies

5. Shell Programming and Scripting

Problems with expect and set variables

I'm writing a script that'll send a time-stamp to my backup server. I create a file with the name of the current date, send it to my server with scp and rm the file from the local computer. Individually these commands work fine and with a set name the expect scripts also work fine. The problem... (0 Replies)
Discussion started by: Ktesh564
0 Replies

6. Shell Programming and Scripting

List all log records logged after $timestamp ?

I am trying to find a way to list every records inside a file (usually a log file) that are present after a record mathing/greater-then a timestamp supplied by another script. The timestamp can be anywhere inside the record and it is usually in the standard `date` format (will not look for other... (5 Replies)
Discussion started by: Browser_ice
5 Replies

7. Programming

Get the list of logged in users

How can I get the list of logged in users in the system programmatically? I can get the list with 'who' or 'users' commands but I need to get the list programmatically... May someone help, please? Thanks in advance. (2 Replies)
Discussion started by: xyzt
2 Replies

8. Solaris

List all inactive users who has not logged on since last 90 days

I need actuall script which List all inactive users who has not logged on since last 90 days Thanks in advance. Di! (17 Replies)
Discussion started by: haridham
17 Replies

9. UNIX for Dummies Questions & Answers

List all inactive users who has not logged on since last 90 days

Hi, Can I get a script to list out all the users, who has not logged on since last 90 days. Last command in not working due due to /var/adm/wtmpx is more than 2 GB. Thanks in advance. Regards, Roni (10 Replies)
Discussion started by: manasranjanpand
10 Replies

10. Shell Programming and Scripting

Trying to get list of logged on users sorted

I'm trying to execute a single shell command that will give me a sorted list of all the users currently logged into the system, displaying the users name as it appears in /etc/passwd. I've tried awk -F: '{print $1}' /etc/passwd | xargs finger -s | cut -c11-28 | uniq This list whoever does... (7 Replies)
Discussion started by: kungfuice
7 Replies
Login or Register to Ask a Question