sunadmn has asked for the wisdom of the Perl Monks concerning the following question:
Hey all I have this really simple expect script I am writing to log into a L4 switch and switch a server into or out of production and for some reason after I send the first command to the session my next regex doesn't match. Here is the code I have thus far:
This is the expected second prompt:
If anyone has a clue here please share as I am pretty lost at this point.
Thanks all
This is the expected second prompt:
>> Real server 144 -
This is where the interactions fails at#!/usr/bin/perl -w # Script using Expect to roll servers in PHX in # the pop in and out of the VIP use strict; use warnings; use Expect; # Setup our reusable varibles here ( host password etc ) my $telnet = '/bin/telnet'; my $host = "myhost.net"; my $passwd = "mypass"; my $timeout = '10'; my $infocmd = '/info/slb/dump'; my $rcmd = '/cfg/slb/real'; my $apply = 'apply'; my $save = 'save'; my $yes = 'y'; my $no = 'n'; my $exit = 'exit'; my $serverL = '/var/tmp/server_list_vip'; # interact a bit till I get the CGI wrapper figured out print "Welcome to the PHX vip roll-in/out script\n I will show you a list of servers you can roll in and out of th +e vip\n choose the correct number for the given server\n EXAMPLE: If you want to roll newsfe01 in/out in the list you wi +ll see\n 144: newsfe01, so the correct number is 144\n"; open(IN,"$serverL"); chomp(my @list = <IN>); close(IN); foreach my $line(@list) { print "$line\n"; } print "Choose the server number now:\n"; chomp(my $number = <STDIN>); print "What action do you want to take?\n Roll server into production = ena\n Roll server out of production = dis\n"; chomp(my $action = <STDIN>); my $exp = Expect->spawn("$telnet $host") or die "Cannot spawn telnet to $host: $!\n";; my $spawn_ok; if($action =~ m/dis/) { my $func = 'dis'; $exp->expect($timeout, [qr'Enter password: $', sub{ $spawn_ok = 1; my $fh = shift; print $fh "$passwd\r"; #$fh->send("$passwd\n"); exp_continue;} ], [qr'>> Main- $', sub{ $spawn_ok = 1; my $fh = shift; print $fh "$rcmd $number/$func\r"; sleep 2; exp_continue; }],
[qr'>> Real server $number - $', sub{ $spawn_ok = 1; my $fh = shift; print $fh "$apply\r"; sleep 2; exp_continue; }], [qr'>> Real server $number - $', sub{ $spawn_ok = 1; my $fh = shift; print $fh "$save\r"; sleep 2; exp_continue; }], [qr'Confirm saving to FLASH [y/n]: $', sub{ $spawn_ok = 1; my $fh = shift; print $fh "$yes\r"; sleep 2; exp_continue; }], [qr'>> Real server $number - $', sub{ $spawn_ok = 1; my $fh = shift; print $fh "$exit\r"; exp_continue; }] ); }
If anyone has a clue here please share as I am pretty lost at this point.
Thanks all
SUNADMN
USE PERL
USE PERL
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Expect problems
by tirwhan (Abbot) on Dec 15, 2005 at 22:48 UTC | |
Re: Expect problems
by GrandFather (Saint) on Dec 15, 2005 at 22:54 UTC | |
by sunadmn (Curate) on Dec 16, 2005 at 14:26 UTC | |
Re: Expect problems
by runrig (Abbot) on Dec 15, 2005 at 23:38 UTC | |
by sunadmn (Curate) on Dec 16, 2005 at 01:48 UTC | |
by runrig (Abbot) on Dec 16, 2005 at 17:12 UTC | |
Re: Expect problems
by GrandFather (Saint) on Dec 15, 2005 at 22:21 UTC | |
Re: Expect problems
by merlyn (Sage) on Dec 16, 2005 at 00:57 UTC | |
Re: Expect problems
by sunadmn (Curate) on Dec 16, 2005 at 04:57 UTC | |
by CountOrlok (Friar) on Dec 16, 2005 at 15:48 UTC | |
by sunadmn (Curate) on Dec 18, 2005 at 22:32 UTC |
Back to
Seekers of Perl Wisdom