Shell script to decrypt and move files in a directory

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

So, the directory structure looks like this:

/Applications/MAMP/bin/decryptandmove.sh
/Applications/MAMP/bin/passtext.txt
/Applications/MAMP/bin/encrypted/test1.txt.pgp
/Applications/MAMP/bin/encrypted/test2.txt.pgp
/Applications/MAMP/htdocs/www/decrypted/

For all of the files found in the encrypted directory, I'm trying to decrypt it and then move them into 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), so I wanted to just output the decrypted file with the same filename, but without the pgp.  So, the result would be:


/Applications/MAMP/bin/decryptandmove.sh
/Applications/MAMP/bin/passtext.txt
/Applications/MAMP/bin/encrypted/
/Applications/MAMP/htdocs/decrypted/test1.txt.pgp
/Applications/MAMP/htdocs/decrypted/test2.txt.pgp


So, this is all I have so far, and it doesn't work...  FILE and FILENAME are both wrong...  I haven't even gotten to the moving part of it yet.... Help?
pass_phrase=`cat passtext.txt|awk '{print $1}'`

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

Open in new window

n00b0101Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

n00b0101Author Commented:
Not really...  I need to drop the .pgp extension, not add it? And, I also don't see anything about decrypting it?
0
tty2Commented:
To drop .pgp extension use "${FILE%.pgp}":

gpg --passphrase $pass_phrase --output ${FILE%.pgp} --decrypt $FILE
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.