Skip to content

Instantly share code, notes, and snippets.

@starkers
Created May 21, 2015 19:06
Show Gist options
  • Save starkers/b0ccfce8e12f32dc605d to your computer and use it in GitHub Desktop.
Save starkers/b0ccfce8e12f32dc605d to your computer and use it in GitHub Desktop.
rar a file up, password protect it, then email it as an attachment with mailx
#!/usr/bin/env bash
## This rar's a file up with a password and emails it
## not as good as using openssl to encrypt but I'm not about to explain openssl pipes to my users
# rar does the job :/
FILE=/var/log/some_logfile.log
PASS="your super top secret password"
#space speration will allow you to send to multiple folks
DEST="customer1@blerg.org myarchive@email.com"
TODAY="$(date "+%Y %m %d)"
SUBJECT="$HOSTNAME .rar of $FILE ($TODAY)"
CONTENT="This is the backup of $FILE attached -generated on $HOSTNAME at: `date` by `whoami`"
TMP_FILE=`mktemp -d`/${HOSTNAME}_${TODAY}.rar
rar a -p"${PASS}" "$TMP_FILE" "${FILE}"
for email in $DEST ; do
echo "$CONTENT" | mailx -s "$SUBJECT" -a "$TMP_FILE" "$email"
done
rm -f "$TMP_FILE"
@starkers
Copy link
Author

starkers commented Jun 9, 2015

for those who don't like rar (me):

  • tar the file
  • encrypt it on the way out
openssl enc -e -bf-cbc -in <FILE>.tar.gz -out <FILE>.tar.gz.enc
  • And to decrypt:
openssl enc -d -bf-cbc -in <FILE>.tar.gz.enc -out <FILE>.tar.gz

password prompts on both ends

@starkers
Copy link
Author

mailx notes..

This should work fine on centos however if you're on debian/ubuntu and have mailx from "mailutils" you should use mailx -A.

Check your manpage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment