• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

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

0
martinmiller40
Asked:
martinmiller40
  • 4
  • 3
1 Solution
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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

0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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

0
 
martinmiller40Author Commented:
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
0
A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

 
Gerwin Jansen, EE MVETopic Advisor Commented:
Hi, I think you have to add the homedir variable like sample below shows:

echo blablah | gpg --homedir /root/.gnupg --batch --no-tty --passphrase-fd 0 -o $f.dec -d $f

Open in new window


I'm not sure what your homedir is, it should be of the user that u used to get it working on the command line, I doubt that it is root btw.
0
 
martinmiller40Author Commented:
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
0
 
martinmiller40Author Commented:
THANK YOU SO MUCH, YOU ROCK !!!!!!!!!!!!!!
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
You're welcome :) Thanks for the points!
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

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