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:

>> Real server 144 -

#!/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; }],
This is where the interactions fails at
[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

In reply to Expect problems by sunadmn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.