Skip to content

Instantly share code, notes, and snippets.

@Wingless-Archangel
Last active May 14, 2020 03:27
Show Gist options
  • Save Wingless-Archangel/8aa9635c02aac30d8948875ce37d75a5 to your computer and use it in GitHub Desktop.
Save Wingless-Archangel/8aa9635c02aac30d8948875ce37d75a5 to your computer and use it in GitHub Desktop.
Simple Bash encryption/decryption operation for cron purpose
# set the Default Static Variable
# if already set Environment variable, please comment this section
SRC_PATH=/opt/b # src to read recommend full path
DEST_PATH=/opt/a # encrypted to
# assume that the expect output file format is .txt
# Also, make sure that you import the private key before running the file via
# gpg --import private.key
for FILE in $(ls *.gpg)
do
if [[ -f ${FILE%.ctrl} ]]; then # check ctrl file if not exist go to another one
# encrypted then move to another folder
# assume that the inputfile format is FILE.txt.gpg
gpg --output ${DEST_PATH}/${FILE%.gpg}.test --decrypt ${SRC_PATH}/${FILE}
fi
done
# set the Default Static Variable
# if already set Environment variable, please comment this section
SRC_PATH=/opt/a # src to read recommend full path
DEST_PATH=/opt/b # encrypted to
KEY=89B4CDB489D9414465325C792B86D253D77013CD # key ID
### Before doing anything please don't forget to import the key into gpg keyring first as shown below ###
# gpg --import public|private.key
# then find the public key id to fill in with
# gpg --list-keys
for FILE in $(ls *.txt)
do
if [[ -f ${FILE%.txt}.ctrl ]]; then # check ctrl file if not exist go to another one
# encrypted then move to another folder
gpg --output ${DEST_PATH}/$FILE.gpg --encrypt --recipient ${KEY} ${SRC_PATH}/$FILE
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment