Link to home
Start Free TrialLog in
Avatar of Martin Miller
Martin MillerFlag for United States of America

asked on

gpg used in cron with STDIO (echo of password)

Having trouble with a cron job script that is using and 'echo' of a password.  I need to pass in or have a file with the password, no other options.

This code segment works find in user console (ssh). In cron creates a blank file.... thus is NOT WORKING to decrypt a file.

I am open to change, but, needs to work in cron to decrypt all files in a folder.

thanks for the read !

+M

#!/bin/bash

for f in /home/ssftp/uploads/*.txt
do
  echo "Decrypting file $f ... "
  echo blahblah |  gpg --batch --no-tty --passphrase-fd 0 --decrypt $f > $f.dec
        mv  /home/ssftp/uploads/*.dec  /home/ssftp/processed
        mv $f  /home/ssftp/processed/archive
done
rm /home/ssftp/processed/\*.txt.dec

Open in new window

Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Hi, think it's your working directory that is the problem here, or lack of. Try changing to /home/ssftp/uploads (on line 2) using:

#!/bin/bash
cd /home/ssftp/uploads
for f in *.txt
do
#  echo "Decrypting file $f ... "
  echo blahblah |  gpg --batch --no-tty --passphrase-fd 0 --decrypt $f > $f.dec
        mv  /home/ssftp/uploads/*.dec  /home/ssftp/processed
        mv $f  /home/ssftp/processed/archive
done
# rm /home/ssftp/processed/\*.txt.dec

Open in new window

Btw, think you need to specify the output file as well, because of the --no-tty option, like this:

echo blahblah |  gpg --batch --no-tty --passphrase-fd 0 -o $f.dec -d $f

Open in new window

Avatar of Martin Miller

ASKER

Next challenge...
Maybe getting closer on this... any other idea to deal with the key ?  key I think is attached to ring for 'root', but this is cron.

/etc/cron.hourly/decryptfiles.sh:

Decrypting file /home/ssftp/uploads/Vendor_Feed_20111019020014.txt ...
gpg: encrypted with RSA key, ID 7F8665E7
gpg: decryption failed: secret key not available
ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gerwinjansen,
I have added the home directory directive, and cron will fire on the hour... I'll report back status.
Thank you for this suggestion too !!!!

+M
THANK YOU SO MUCH, YOU ROCK !!!!!!!!!!!!!!
You're welcome :) Thanks for the points!