>> 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 the vip\n
choose the correct number for the given server\n
EXAMPLE: If you want to roll newsfe01 in/out in the list you will see\n
144: newsfe01, so the correct number is 144\n";
open(IN,"$serverL");
chomp(my @list = );
close(IN);
foreach my $line(@list) {
print "$line\n";
}
print "Choose the server number now:\n";
chomp(my $number = );
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 = );
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;
}]
);
}