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

Posted by KittyYoung on Stack Overflow See other posts from Stack Overflow or by KittyYoung
Published on 2010-03-25T01:00:53Z Indexed on 2010/03/25 1:03 UTC
Read the original article Hit count: 496

Filed under:
|
|

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? I've written exactly one shell script ever, and it was so simple, a monkey could have done it... Feeling out of depth here...

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

© Stack Overflow or respective owner

Related posts about shell

Related posts about move