From: Jason G. <JG...@cw...> - 2007-05-17 18:54:18
|
Hello, Here is the problem I am having: I use expect to spawn an SSH session to a cisco router and run the command = 'show arp', which sends a lot of data back. example: gw>show arp Protocol Address Age (min) Hardware Addr Type Interface Internet XX.XX.108.17 0 XXXX.319f.c3d9 ARPA Vlan133 Internet XX.XX.97.28 171 XXXX.c525.d4c3 ARPA Vlan122 Internet XX.XX.99.30 41 XXXX.420c.e73f ARPA Vlan124 ... (there are thousands of lines sent back) The problem I get is that expect seems to process this data in chunks. = For example, it will process: Protocol Address Age (min) Hardware Addr Type Interface Internet XX.XX.108.17 0 XXXX.319f.c3d9 ARPA Vlan133 Internet XX.XX.97.28 171 XXXX.c5 where it will pull out the data correctly for the first line, but will not = match the second line since it is incomplete. Then, it processes the next = chunk. example: 25.d4c3 ARPA Vlan122 Internet XX.XX.99.30 41 XXXX.420c.e73f ARPA Vlan124 where it will not pull the data correctly for the first line (incomplete), = but will pull the correct data for the second line. I have used the TCL expect before and it does the same thing so I know it = is not a bug. I think there is just a gap in my understanding of how = expect processes the data that is sent back from spawned processes. Is there a way to make expect deal with all of the data as one big chunk, = rather than processing it in pieces? I hope someone can explain how this = works. --Jason |
From: Ken I. <fn...@ua...> - 2007-05-17 19:10:18
|
On Thu, May 17, 2007 at 11:53:52AM -0700, Jason Gerdes wrote: > Hello, > > Here is the problem I am having: > > I use expect to spawn an SSH session to a cisco router and run the > command 'show arp', which sends a lot of data back. example: > > gw>show arp > Protocol Address Age (min) Hardware Addr Type Interface > Internet XX.XX.108.17 0 XXXX.319f.c3d9 ARPA Vlan133 > Internet XX.XX.97.28 171 XXXX.c525.d4c3 ARPA Vlan122 > Internet XX.XX.99.30 41 XXXX.420c.e73f ARPA Vlan124 > ... (there are thousands of lines sent back) > > The problem I get is that expect seems to process this data in chunks. > For example, it will process: > > Protocol Address Age (min) Hardware Addr Type Interface > Internet XX.XX.108.17 0 XXXX.319f.c3d9 ARPA Vlan133 > Internet XX.XX.97.28 171 XXXX.c5 > > where it will pull out the data correctly for the first line, but will > not match the second line since it is incomplete. Then, it processes > the next chunk. example: > > 25.d4c3 ARPA Vlan122 > Internet XX.XX.99.30 41 XXXX.420c.e73f ARPA Vlan124 > > where it will not pull the data correctly for the first line > (incomplete), but will pull the correct data for the second line. > > I have used the TCL expect before and it does the same thing so I know > it is not a bug. I think there is just a gap in my understanding of > how expect processes the data that is sent back from spawned processes. > > Is there a way to make expect deal with all of the data as one big > chunk, rather than processing it in pieces? I hope someone can explain > how this works. If you "expect" some string or pattern that appears only after the desired output is complete, e.g., perhaps the command prompt "gw>", everything ought to be found in the before() method. -- Ken Irving |
From: Matt Z. <mzagrabe@d.umn.edu> - 2007-05-17 19:45:23
|
> Is there a way to make expect deal with all of the data as one big chunk,= rather than processing it in pieces? I hope someone can explain how this = works. not to my knowledge, though a work-around that i have used is to write everything to a buffer (continually appending the data that expect returns). next, split'ing the data in that scalar (buffer) into an array of lines. finally, doing a 'foreach' on the array of lines and processing as i normally would. --=20 Matt Zagrabelny - mzagrabe@d.umn.edu - (218) 726 8844 University of Minnesota Duluth Information Technology Systems & Services PGP key 1024D/84E22DA2 2005-11-07 Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 He is not a fool who gives up what he cannot keep to gain what he cannot lose. -Jim Elliot |
From: Jason G. <JG...@cw...> - 2007-05-17 20:45:14
|
Thanks to both who answered this question. I was able to use both of your = suggestions and my script is working now. Thanks a lot!! --Jason >>> Jason Gerdes <JG...@cw...> 5/17/2007 11:53 AM >>> Hello, Here is the problem I am having: I use expect to spawn an SSH session to a cisco router and run the command = 'show arp', which sends a lot of data back. example: gw>show arp Protocol Address Age (min) Hardware Addr Type Interface Internet XX.XX.108.17 0 XXXX.319f.c3d9 ARPA Vlan133 Internet XX.XX.97.28 171 XXXX.c525.d4c3 ARPA Vlan122 Internet XX.XX.99.30 41 XXXX.420c.e73f ARPA Vlan124 ... (there are thousands of lines sent back) The problem I get is that expect seems to process this data in chunks. = For example, it will process: Protocol Address Age (min) Hardware Addr Type Interface Internet XX.XX.108.17 0 XXXX.319f.c3d9 ARPA Vlan133 Internet XX.XX.97.28 171 XXXX.c5 where it will pull out the data correctly for the first line, but will not = match the second line since it is incomplete. Then, it processes the next = chunk. example: 25.d4c3 ARPA Vlan122 Internet XX.XX.99.30 41 XXXX.420c.e73f ARPA Vlan124 where it will not pull the data correctly for the first line (incomplete), = but will pull the correct data for the second line. I have used the TCL expect before and it does the same thing so I know it = is not a bug. I think there is just a gap in my understanding of how = expect processes the data that is sent back from spawned processes. Is there a way to make expect deal with all of the data as one big chunk, = rather than processing it in pieces? I hope someone can explain how this = works. --Jason ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/=20 _______________________________________________ Expectperl-discuss mailing list Exp...@li...=20 https://lists.sourceforge.net/lists/listinfo/expectperl-discuss |
From: Roland G. <rgi...@cp...> - 2007-05-23 15:22:23
|
how about adjusting your regex to deal with one complete line after another? something like "Internet.*\n"? hope this helps, roland On 5/17/07, Jason Gerdes <JG...@cw...> wrote: > Hello, > > Here is the problem I am having: > > I use expect to spawn an SSH session to a cisco router and run the command 'show arp', which sends a lot of data back. example: > > gw>show arp > Protocol Address Age (min) Hardware Addr Type Interface > Internet XX.XX.108.17 0 XXXX.319f.c3d9 ARPA Vlan133 > Internet XX.XX.97.28 171 XXXX.c525.d4c3 ARPA Vlan122 > Internet XX.XX.99.30 41 XXXX.420c.e73f ARPA Vlan124 > ... (there are thousands of lines sent back) > > The problem I get is that expect seems to process this data in chunks. For example, it will process: > > Protocol Address Age (min) Hardware Addr Type Interface > Internet XX.XX.108.17 0 XXXX.319f.c3d9 ARPA Vlan133 > Internet XX.XX.97.28 171 XXXX.c5 > > where it will pull out the data correctly for the first line, but will not match the second line since it is incomplete. Then, it processes the next chunk. example: > > 25.d4c3 ARPA Vlan122 > Internet XX.XX.99.30 41 XXXX.420c.e73f ARPA Vlan124 > > where it will not pull the data correctly for the first line (incomplete), but will pull the correct data for the second line. > > I have used the TCL expect before and it does the same thing so I know it is not a bug. I think there is just a gap in my understanding of how expect processes the data that is sent back from spawned processes. > > Is there a way to make expect deal with all of the data as one big chunk, rather than processing it in pieces? I hope someone can explain how this works. > > > > --Jason > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |