Subject: | Using expect with cryptsetup |
Date: | Tue, 20 Aug 2013 09:32:55 +0300 |
To: | bug-Expect [...] rt.cpan.org |
From: | Theodotos Andreou <theo [...] ubuntucy.org> |
Hi guys,
I am not sure if this is an Expect.pm bug or my lack of understanding
perl. Feel free to close it if it is not a real bug.
I am trying to automate the decryption of a volume using Expext.pm I
want to run this command automated:
# cryptsetup luksOpen /dev/VG/DATA dec-DATA Enter passphrase for
/dev/VG/DATA:
[download]
<http://perlmonks.org/index.pl?abspart=1;displaytype=displaycode;node_id=1050126;part=1>
After you successfully give the passphrase you get /dev/mapper/dec-DATA
which is the unencrypted volume I want to automate this using Expect.pm
I came up with this code:
#!/usr/bin/perl use strict; use warnings; use Expect; use Getopt::Std;
$Expect::Debug = 0; $Expect::Log_Stdout = 1; my $command =
"/sbin/cryptsetup"; my $timeout = 5; my $exp = Expect->spawn( $command,
'luksOpen', '/dev/VG/DATA', 'dec-DATA' ) or die "Cannot spawn $command:
$!\n"; my $idx = $exp->expect($timeout, [qr/Enter\s+passphrase\s+for/,
sub { my $exp =shift; $exp->send("secret\n"); }] ); $exp->soft_close();
[download]
<http://perlmonks.org/index.pl?abspart=1;displaytype=displaycode;node_id=1050126;part=2>
Now I have the following peculiarity. When $Expect::Debug is set to 0 it
does not work; when set to 1 it does! Can you please enlight a perl
newbie? Is this a bug or am I doing something fundamentally wrong? I use
perl v5.14.2 and Expect.pm is version 1.21.