bmalnad has asked for the wisdom of the Perl Monks concerning the following question:
Hey Guys,
I just inherited this Perl script from a former coworker. It works fine if I run it from my account using: sudo perl decrypt.pl foo.pgp bar.txt
If I do a sudo su - root and type: perl decrypt.pl foo.pgp bar.txt
It fails with this error: Use of uninitialized value $plaintext[0] in print at decrypt.pl line 23, <$ciphertext_fh> line 2486.
Thoughts??#!/usr/bin/perl use strict; use warnings; use Crypt::GPG; use Data::Dumper; my $gpg = new Crypt::GPG; $gpg->gpgbin('/usr/bin/gpg'); $gpg->secretkey('xxxxxxxxxx'); $gpg->passphrase('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); my $inputfile = shift; my $outputfile = shift; open my $ciphertext_fh, '<', $inputfile or die "couldn't open $inputfi +le: $!"; open my $output_fh, '>', $outputfile or die "couldn't open $outputfile + for writing: $!"; my @ciphertext = <$ciphertext_fh>; my (@plaintext) = $gpg->decrypt(\@ciphertext) or die "didn't work: $!" +; print $output_fh @plaintext; close $ciphertext_fh; close $output_fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Script works when run with sudo, but not when run directly as root...?
by MidLifeXis (Monsignor) on May 07, 2014 at 19:50 UTC | |
by bmalnad (Initiate) on May 07, 2014 at 20:42 UTC | |
by hippo (Archbishop) on May 07, 2014 at 21:00 UTC | |
by Laurent_R (Canon) on May 07, 2014 at 22:13 UTC | |
|
Re: Script works when run with sudo, but not when run directly as root...?
by LanX (Saint) on May 07, 2014 at 18:51 UTC | |
by bmalnad (Initiate) on May 07, 2014 at 19:00 UTC | |
by LanX (Saint) on May 07, 2014 at 19:07 UTC |