From: Pothuri, S. K <spo...@vi...> - 2009-06-08 05:24:00
|
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. sub log_in { my ($line,$userid,$passwd) = @_; my $exp = new Expect; my $command = "ssh -l $userid $line"; .................... ..................... ..................... ..................... $exp->send("telnet $telnetip $telnetport\n"); if($exp->expect(5, 'Escape character is')) { print "Telnet successful.\n"; $exp->send("\^]\n"); $exp->expect(30, 'telnet'); $exp->send("quit\r\n"); ................. ................. ................. ................. else { ............... ............... print "Telnet Failed.\n"; $exp->send("\cC\r"); =========> This is not working as expected. It does not terminate telnet process. I even tried hex and octal representations. if($exp->expect(5, $PROMPT)) Appreciate any help. Thanks in advance. Thanks Satish |