Shell脚本解密并将文件从一个目录移动到另一个目录 [英] Shell script to decrypt and move files from one directory to another directory
问题描述
所以,目录结构如下所示:
/Applications/MAMP/bin/decryptandmove.sh
/Applications/MAMP/bin/passtext.txt
/ Applications / MAMP / bin / encrypted / test1.txt.pgp
/Applications/MAMP/bin/encrypted/test2.txt.pgp
/应用程序/ MAMP / htdocs / www / decryptpted /
对于在加密目录中找到的所有文件,我正在尝试解密它们,然后将它们移动到目录www / decryptpted /。我不知道加密目录中的文件名将提前(此脚本最终将通过cron作业运行),因此我只想输出具有相同文件名的解密文件,但不使用pgp。因此,结果将是:
/Applications/MAMP/bin/decryptandmove.sh
/ Applications / MAMP / bin / passtext.txt
/应用程序/ MAMP / bin / encrypted /
/Applications/MAMP/htdocs/decrypted/test1.txt.pgp
/应用程序/ MAMP / htdocs / decryptpted / test2 .txt.pgp
所以,这是我迄今为止写的,它不工作。 FILE和FILENAME都错了。我甚至没有得到移动的部分。
pass_phrase =`cat passtext.txt | awk'{print $ 1} '/应用程序/ MAMP / bin / encrypted /'中的文件
;
do
FILENAME = $(basename $ FILE .pgp)
gpg --passphrase $ pass_phrase --output $ FILENAME --decrypt $ FILE
done
#!/ bin / bash
p = $(< passtext.txt)
set - $ p
pass_phrase = $ 1
destination =/ Applications / MAMP / htdocs / www / decryptpted /
cd / Applications / MAMP / bin / encrypted
用于* .pgp中的FILE;
do
FILENAME = $ {FILE%.pgp}
gpg --passphrase$ pass_phrase - 输出$ destination / $ FILENAME--decrypt$ FILE
完成
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:
/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 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:
/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 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/';
do
FILENAME=$(basename $FILE .pgp)
gpg --passphrase $pass_phrase --output $FILENAME --decrypt $FILE
done
#!/bin/bash
p=$(<passtext.txt)
set -- $p
pass_phrase=$1
destination="/Applications/MAMP/htdocs/www/decrypted/"
cd /Applications/MAMP/bin/encrypted
for FILE in *.pgp;
do
FILENAME=${FILE%.pgp}
gpg --passphrase "$pass_phrase" --output "$destination/$FILENAME" --decrypt "$FILE"
done
这篇关于Shell脚本解密并将文件从一个目录移动到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!