Automate decryption using GnuPGInterface

G

George

Hi,
Does anyone have any experience with GnuPGInterface? I'm having a
problem with decrypting files through a cron job. The below job works
great when I run it manually from the command line, but it blows up
whenever I try to run it through cron, and I can't really figure out
why. I've been trying to learn python, and I'm at the point where I can
get things working in small scripts (you know, just enough to be
dangerous). If anybody could shed some light as to what I might be
doing wrong, I would really appreciate it. TIA...

#!/usr/local/bin/python

import os, glob, time, GnuPGInterface

gnupg = GnuPGInterface.GnuPG()
gnupg.options.extra_args.append('--no-secmem-warning')
gnupg.passphrase = ######

# get list of files in /home/ns1
# that match regex pattern
for pgpname in glob.glob("/home/ns1/[ABDP]*.pgp"):
txtname = pgpname.replace('.pgp','.txt')
inputfile = file(pgpname,'r')
outputfile = file(txtname,'w')

process = gnupg.run(['--decrypt'],
attach_fhs={'stdin':inputfile,'stdout':eek:utputfile})

process.wait() # cleanup
inputfile.close()
outputfile.close()

os.remove(pgpname)
 
N

NavyJay

Are you able to run a dummy Python script using crontabs? For
troubleshooting purposes, I would verify this before trying to debug my
code. Check your permissions, paths, etc.

Can you post your entry into cron? What exactly happens when it "blows
up"?
 
G

George

I have 5 python scripts I've added to cron over the past year that run
correctly all the time. I double-checked the permissions and paths and
everything looks good there. Here's the cron entry that I just tested
with:
23 12 * * * /usr/local/bin/decrypt_test.py >
/usr/local/bin/decrypt.log 2>&1

As for "blowing up", I get the typical stack trace, but I'm not
python-savvy enough to quite figure it out:

Traceback (most recent call last):
File "/SHCD/scripts/decrypt_certegy.py", line 18, in ?
attach_fhs={'stdin':inputfile,'stdout':eek:utputfile})
File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
357, in run
create_fhs, attach_fhs)
File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
401, in _attach_fork_exec
if process.pid == 0: self._as_child(process, gnupg_commands, args)
File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
442, in _as_child
os.execvp( command[0], command )
File "/usr/local/lib/python2.2/os.py", line 298, in execvp
_execvpe(file, args)
File "/usr/local/lib/python2.2/os.py", line 352, in _execvpe
raise exc, arg
OSError: [Errno 2] No such file or directory
/home/ns1/PTAccountTransfer.051130022347.pgp
Traceback (most recent call last):
File "/SHCD/scripts/decrypt_certegy.py", line 20, in ?
process.wait() # cleanup
File "/usr/local/lib/python2.2/site-packages/GnuPGInterface.py", line
639, in wait
raise IOError, "GnuPG exited non-zero, with code %d" % (e << 8)
IOError: GnuPG exited non-zero, with code 65536


I'm guessing it has something to do with stdin, stdout, and cron, but I
can't figure out any more than that, or how I would go about changing
it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,273
Messages
2,571,363
Members
48,049
Latest member
DomenicMon

Latest Threads

Top