KittyYoung KittyYoung - 5 months ago 42
Bash Question

Shell script to decrypt and move files from one directory to another directory

I have a directory and in it has several files. I'm trying to decrypt those files and move them to another directory. I can't figure out how to set the output filename and move it.

So, the directory structure looks like the following:


For all the files that are found in the encrypted directory, I'm trying to decrypt them and then move them to the directory www/decrypted/. I don't know what the filenames in the encrypted directory will be ahead of time (this script will eventually run via cron job), so I wanted to just output the decrypted files with the same filenames, but without the pgp. So, the result would be:


So, this is all I have written so far and it doesn't work. FILE and FILENAME are both wrong. I haven't even gotten to the moving part.

pass_phrase=`cat passtext.txt|awk '{print $1}'`

for FILE in '/Applications/MAMP/bin/encrypted/';
FILENAME=$(basename $FILE .pgp)
gpg --passphrase $pass_phrase --output $FILENAME --decrypt $FILE

set -- $p
cd /Applications/MAMP/bin/encrypted
for FILE in *.pgp;
    gpg --passphrase "$pass_phrase" --output "$destination/$FILENAME" --decrypt "$FILE"