GPG Encrypt without filename
Hey Guys,
Is it possible to pass the filename of a file to be encrypted to the GPG Command through a variable? I need to encrypt the latest file within a directory. So, to asscertain the filename of the latest file I've got: Code:
find . -type f -print0|xargs -0 ls -drt|tail -n 1 > $LATEST Code:
gpg -r email@email.com -e $LATEST Is there a way that I could print or echo the contents of this variable to the end of the command? Thanks in advance. Jon |
instead of
Quote:
Code:
cat $LATEST | gpg -r email@email.com - |
Hey,
Thanks for the recommendation however it does not work. Any other ideas? :) J |
Is there anything generic that can be done to append the contents to the end?
I've read something about 'sed' but I don't know enough about it to know how to manipulate it for what I want. |
Possibly
Code:
gpg -r email@email.com < $LATEST |
You don't need an intermediate variable. This should work:
Code:
gpg -r email@email.com -e "$(find . -type f -print0|xargs -0 ls -drt|tail -n 1)" |
Cephus you're a legend, that's exactly how I wanted it to work :)
I've actually changed the way I get the file name now so I've amended the code towards the end but the result is perfect :) I've got Code:
DATE=$(date +%d%m%y) I do have another question while we're on a role... So at the moment that's going to find the file in the list of files with todays date in it, and then encrypt it. It works and does it fine. What if there are 2 or 3 files with todays date? Would I be able to create a 'for loop' where it will run the command for all files it finds with todays date in? Thanks Jon |
Quote:
Code:
find . -type f -name "*.csv" | grep $DATE | while read i; do gpg -r user@domain.com -e "$i"; done And if the $DATE is part of the filename, you can incorporate it into the find command and get rid of the additional pipe to grep. Also, it will not falsely find subdirectories with the $DATE in their name: Code:
find . -type f -name "*$DATE*.csv" | while read i; do gpg -r user@domain.com -e "$i"; done |
I've managed to adjust things again to get rid of the use for a variable... which I'm happier with:
Code:
find . -type f -name "*.csv" | grep $(date +%d%m%y) |
Apologies Cepheus I've just noticed your response.. just reading it now.
Thanks for your help, will let you know how I get on. Thanks Jon |
This is getting close, I can feel it :) lol
I've adjusted it as follows: Code:
find . -type f -name "*$(date +%d%m%y)*.csv" | while read i; do gpg: can't open `./120614101530.csv;': No such file or directory gpg: ./120614101530.csv;: encryption failed: No such file or directory Like it's expecting to find a directory? Have I done something wrong? |
remove the extra semicolon in "$i;"
|
Ah yes that works great.. :)
I just have one more question.. lol :-) I had originally written a script that would encrypt a single file (by filename) and upload it to a different server via FTP. With this method in mind, could I use a similar loop to upload the files it's just encrypted? What I've got so far looks like this: Code:
HOST=ftp.server |
I took a punt on something like this...
Code:
find /sitsimp -type f -name "*$(date +%d%m%y)*.csv.gpg | while read i do put $i; done Am I on the right kind of track or would I need to take a different approach to the initial find command? |
Sorry to bombard the thread.. but trying to keep it updated with the things I'm trying out, and the ideas I've been having.
My latest thought is something along the lines of: Code:
find /sitsimp -type f -name "*$(date +%d%m%y)*.csv.gpg" > $FILES |
All times are GMT -5. The time now is 02:46 PM. |