Hello,
Not long ago, I got an interesting challenge from a large
company to automate their Apache+SSL startup with PEM
pass phrase enabled.
I had a requirement to leave the PEM pass phrase, so the obvious
choices were to use Expect, or Perl with Expect module.
I sat down and wrote a little Perl script. It is so little that
I decided to share it in email to SLUG. It works fine.
Stay happy and be at peace with nature, people and computers
(in listed order).
Dusan
#!/bin/perl
#
# Program: start-apache-ssl.pl
# Description: Start Apache SSL with PEM pass phrase enabled.
# Version: 1.3
# Written by: Dusan U. Baljevic
#
# Requirements: Perl
# Expect-1.15 or better
# IO-Tty-1.02 or better
#
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/sbin';
$ENV{'SHELL'} = '/bin/sh' if $ENV{'SHELL'} ne '';
$ENV{'IFS'} = '' if $ENV{'IFS'} ne '';
require 5.004;
use strict;
use Expect;
use vars qw($Command $sh $PEM_Prompt $PEM_Pass $Prompt);
$|=1;
$Expect::Log_Stdout=0;
# First we have to initialize STDIN in to an expect object.
my $stdin=Expect->exp_init(\*STDIN);
my $stdout=Expect->exp_init(\*STDOUT);
my $PEM_Prompt = "Enter PEM pass phrase";
my $PEM_Pass = "what#ever-PEM-password";
$Command = "/usr/local/apache-ssl/bin/httpsdctl start";
my $Prompt = "$Hostname#";
$sh=Expect->spawn("$Command") or die "ERROR: Spawn failed: $?";
print "NOTE: Executing $Command...\n";
$sh->log_stdout(0); # Log to STDOUT
unless ($sh->expect(5, '-re', "$PEM_Prompt:")) {
print "ERROR: Timeout executing the $Command.\n";
}
print "NOTE: Passing the PEM pass phrase...\n";
print $sh "$PEM_Pass\r";
$sh->expect(5, '-re', $Prompt) || warn "ERROR sending the PEMpasswd.\n";
exit(0);
--
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug