From: Satish P. <sat...@gm...> - 2009-06-09 05:26:26
|
> > Thanks Robin for your prompt response. Yes, it does work in the scenario of successful telnet (by passing \c] through expect). But in case of failed telnet where it takes around 4 mins to (telnet) timeout, I want to interrupt the telnet if it is not successful within 30 seconds. I want to wait on expect for a string that indicates sucessful telnet for 30 seconds, if it is not successful (i.e., based on expect timeout), I would like to interrupt the telnet program. Below is the case where I want interrupt, I dont want to wait for about 4 mins (telnet timeout). By hand I can do this using Ctrl-C, but unable to perform the same through expect. # telnet 192.168.1.106 670 Trying 192.168.1.106... ------> pressed Ctrl-C here # Thank you. > > -----Original Message----- > From: Robin Lee Powell [mailto:rlp...@di...] > Sent: Monday, June 08, 2009 9:38 AM > To: Pothuri, Satish K > Cc: exp...@li... > Subject: Re: [Expectperl-discuss] Perl Expect - How to terminate a > commandthat was run using send > > On Sun, Jun 07, 2009 at 10:08:25PM -0700, Pothuri, Satish K wrote: > > Hi, > > > > > > > > I would appreciate if someone can help me with this. > > > > > > > > I am writing a script in Perl that uses expect feature to SSH to a > > server and perform ping and telnet tests from that server. > > > > > > > > 1. Spawn SSH to a server > > 2. Send commands for ping and telnet (one after another) to the > > spawned command (SSH). > > > > > > > > My question is how I can interrupt/terminate the telnet process if it > is > > taking too long to complete. I am trying to send "\cC" (control - C) > if > > my expect times out waiting for something after sending the telnet > > command, but it doesn't seem to be working. > > Telnet is a terminal emulator; it passes \cC to the remote side. > Try it on the command line; you'll see it doesn't work (assuming a > connection has been made). > > Try \c] followed by "exit" (or whatever command your telnet wants; > do ^] on a live connection by hand to see the menu). > > -Robin > |