Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1575
  • Last Modified:

gpg - failed to create temporary file

I have written a Perl script on CentOS 4.4 to read the contents of a directory and then encrypt the files using gpg.  the command is:

gpg -r 'username' --batch --encrypt-files 'filename.ext'

I created the script as root.  When I run it interactively from the console, it works just fine.  However, if I try to run it from cron or start it from another process (running as root), I receive the following error:

gpg: failed to create temporary file `~/.gnupg/.#lk0x9804868.xxxxxxxxx.31811': No such file or directory
gpg: fatal: ~/.gnupg: can't create directory: No such file or directory

I've echoed the tilde (~) from within the script and it translates to "/root".  The directory "/root/.gnupg" does exist and has proper owner permissions.  

Any ideas would be appreciated.  Thanks.
0
asrobins
Asked:
asrobins
  • 4
  • 4
1 Solution
 
Adam314Commented:
So your perl script does:
    system("gpg -r 'username' --batch --encrypt-files 'filename.ext'");

0
 
asrobinsAuthor Commented:
Yes, that it correct.  It works fine from the console as root, but not from cron as root.  I've tried changing the permissions on the /root/.gnupg directory to 777, but it still does not work.  That leads me to believe that it is not trying to place the file there, but somewhere else.  I see nothing in the conf file that would let me change the location of temp files.  Thanks.
0
 
Adam314Commented:
Is gpg something you created?  Is it a shell script?

When you echo ~ in the script, you mean in the gpg script, not your perl script?
0
Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

 
asrobinsAuthor Commented:
no, gpg is the linux command to run gnupg, the encryption program.  It came with the CentOS distribution.
/usr/bin/gpg is an executable.
0
 
Adam314Commented:
Is your perl script setuid to make it run as root, or are you actually logging in as root?
0
 
asrobinsAuthor Commented:
I am actually logged in as root
0
 
Adam314Commented:
Does the perl script change the environment at all before calling system to start gpg?
0
 
asrobinsAuthor Commented:
Problem has been independently resolved.

Solution was to add parameter:  --homedir '/root/.gnupg' to the gpg command line.

Thanks for trying.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now