Created
May 21, 2015 19:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
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
for those who don't like rar (me):
password prompts on both ends