Script running for one iteration and failing the second one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script running for one iteration and failing the second one
# 1  
Old 09-29-2011
Script running for one iteration and failing the second one

Hi,
I am using Tclexpect to automation testing on switches and using regexp and the buffer outputs the program is running well for one iteration and failing the second one... can anyone please guide me what is the mistake i am making?

Thanks
Here is the small version of the program,
Code:
 while {1} {
                expect "#"
                send "clear counters\r"
                expect -re ".*#"
                expect "#"
                send "show interface port $port1,$port2 interface-rate\r"
                sleep 30
                expect "#"
                set  buff $expect_out(buffer)
                puts "Buff: $buff"
                regexp {(UcastPkts:[\t ]+([0-9]+)[\t ]+([0-9]+))} $buff match
                puts "$match"
                send "\r"
                 expect "#"
                send "sh spanning-tree stp $stp_vlan information\r"
                sleep 30
                expect "#"      
                send "clear counters\r"
                expect "#"
                send "sh interface port $port1,$port2 interface-rate\r"
                sleep 30
                expect "#"
                set buff $expect_out(buffer)
                puts "Buff=$buff"
                regexp {(UcastPkts:[\t ]+([0-9]+)[\t ]+([0-9]+))} $buff match
                puts "$match"
                send "\r"
                expect "#"
                send "sh mp cpu\r"
                sleep 10
                expect "#"
                send "sh mp memory\r"
                sleep 10
                }


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 09-30-2011 at 03:45 AM.. Reason: Please use code tags, thank you
# 2  
Old 09-30-2011
Quote:
Originally Posted by roh_20022002
...the program is running well for one iteration and failing the second one...
Just saying the word failing is vary vague.

Can you be specific on the reason?

Example, if you are receiving an error message and what it is, what is the difference between the first and the second output, etc.
# 3  
Old 09-30-2011
Okay here is the problem. I am using regexp at the beginning and the end of the loop because I want to compare the output of a certain command which shows the rate of packets coming in on a particular port on a switch.

I faced certain problems with clearing the buffer for the regexp match which I had to do. But I figured it out and the program seemed to run fine but its only working properly for one iteration and as soon as it enters the loop second time it gives me the TIMEOUT message. I havent posted the entire script over here. Please let me know if you need to see the entire script I can mail it to you.

Thanks a lot for replying.

Regards,

Rohan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While loop is running only for the first iteration

Hello, I've written a script to automate encoding of all the MP4 files in a directory (incl. subdirectories). But unfortunately it's running for the first MP4 file only. My machine details: root@Ubuntu16:~# uname -a Linux Ubuntu16 4.10.0-28-generic #32~16.04.2-Ubuntu SMP Thu Jul 20 10:19:48... (2 Replies)
Discussion started by: prvnrk
2 Replies

2. Shell Programming and Scripting

While loop is causing ssh command to exit from script after first iteration.

I am trying to check multiple server's "uptime" in a loop over "ssh". When I execute multiple ssh commands with hard coded servernames script is executing fine. But when I pass server names using while loop, script is exiting after checking first server's status, why? # serverList... (8 Replies)
Discussion started by: kchinnam
8 Replies

3. UNIX for Dummies Questions & Answers

Crontab script failing

Hello, A crontab script is failiing everyday but when we execute manually it runs fine Below is the script scheduled: 00 23 * * * sh /db2backup/scripts/db2_hot_backup.ksh TRAVFF > /dev/null 2>&1 Error: cat TRAVFF_online_04022014_2300.log Started : Wed Apr 2 23:00:00 EDT 2014... (2 Replies)
Discussion started by: Vishal_dba
2 Replies

4. UNIX for Dummies Questions & Answers

Script test failing

Testing some old script developed by different user. #!/usr/bin/sh case "$0" in */*) cmd="$0";; *) cmd=`which "$0"`;; esac dir=`dirname "$cmd"` node="$dir/." echo $node below two simple tests are failing, I am not seeing any Control+M characters in the script file and I am not able... (4 Replies)
Discussion started by: srimitta
4 Replies

5. Shell Programming and Scripting

Script running in parallel failing!

Hi, I have a single script that was running fine in parallel on Linux 2.6.9-89 now it has been upgraded to Linux 2.6.18-308.24.1.el5 and the script has started to fail unpredictably. Is this an upgrade issue? As the script runs fine for some parallel threads while fails for others. Please... (4 Replies)
Discussion started by: Panna
4 Replies

6. Shell Programming and Scripting

SCP Failing - In Script

I create a file that may contain several full path name files on a remote Linux that are to be copied. This file, called AWKOUTPUT is created from another script. It contains: X/picture1.png The script is very simple ------------------------------------------- REMOTEDIR="/var/CC/Stuff"... (4 Replies)
Discussion started by: mohrsville12
4 Replies

7. Shell Programming and Scripting

Expect script help needed- script failing if router unavailable

Hey all. Sometimes I'm tasked to change some router configs for the entire network (over 3,000 Cisco routers). Most of the time its a global config parameter so its done with a loop and an IP list as its the same configuration change for all routers. This is working OK. However, sometimes an... (3 Replies)
Discussion started by: mrkz1974
3 Replies

8. UNIX for Dummies Questions & Answers

Why does fibonacci sequence script stop making sense at 92nd iteration?

So, Just for practice, I wrote a simple fibonacci sequence script in bash. (03:08:02\$ cat fib #!/usr/bin/bash ret () { echo -ne "\n" sleep .5 } a=1 b=2 echo -n $a #1 A ret echo -n $b #2 B ret (8 Replies)
Discussion started by: DeCoTwc
8 Replies

9. UNIX for Dummies Questions & Answers

failing a unix script

i am basically DWH professional. I want to write a script such that whenver the file size is greather than 0 the script fails plz help me in this (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

10. UNIX for Advanced & Expert Users

UNIX script failing ....

Hi folks, I have written down a UNIX script which actually FTP the file to other server. What is happening now , this script is not working only for 1 server , as it is working for 32 different FTP server . In this particular server , we are getting message “FTp:550 access denied”... (1 Reply)
Discussion started by: khan1978
1 Replies
Login or Register to Ask a Question