By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,677 Members | 1,177 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,677 IT Pros & Developers. It's quick & easy.

Automate decryption using GnuPGInterface

P: n/a
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':outputfile} )

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

os.remove(pgpname)

Nov 30 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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"?

Nov 30 '05 #2

P: n/a
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':outputfile} )
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.

Nov 30 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.