Sometimes I need to send large files (to myself) from my server. First, I encrypt then break the files down to email size & send via gmail. I'm still working on it, any suggestions would be appreciated. The script does work. I'm very new to bash and this is my first post
# TAR --> ENCRYPT --> GZIP --> SPLIT --> EMAIL --> CLEANUP
# To use: ./en-mail.sh <directory>
# Requires sendEmail and openssl
# Fill in the blanks, I use gmail. PASSWD is for the SENDER account.
# EMAIL is where you want the files sent to.[email protected]
PASSWD=xxxxxx [email protected]
# I set this, but I didn't use it correctly.
# TAR --> ENCRYPT --> GZIP
# Verify directory is correct
echo "$1 will be sent, is this correct(y/n)? \c "
if [ $a = y ] ; then
# TAR and encrypt with openssl. You will be
# prompted to enter a password. File will be
# saved to home directory (and deleted later).
# 1st line might not be needed...
tar c * -C $1 | openssl enc -aes-256-cbc -e > ~/177343.tar.e
# SPLIT, I chose 6M. 177343 is a random directory, I tried
# to pick something that wouldn't be taken.
mv 177343.tar.e.gz 177343
split -b 6M 177343.tar.e.gz
# remove file before building filelist to send via email
rm -rf 177343.tar.e.gz
# BUILD FILELIST AND E-MAIL
echo "Subject of e-mail (one word): \c "
ls -1 |grep x > filelist
filenum=`cat filelist |sed -n '$='`
echo "$filenum files will be sent to $EMAIL, please wait.."
cat $FILE |while read line
sendEmail -f $SENDER -t $EMAIL -u "$b - $n of $filenum" -m "$b - $n of $filenum" -a "$line" -s smtp.gmail.com -o tls=yes -xu $SENDER -xp $PASSWD
n=$(expr $n + 1)
done < $FILE
# Send final e-mail with script attached to reassemble files and decrypt
# You will be prompted for password again. I picked decode because some
# people may already have a script named decrypt (I know I do).
echo '#''!'/bin/bash > decode.sh
echo "cat $SPLITS > 177343.tar.e.gz" >> decode.sh
echo "gunzip 177343.tar.e.gz" >> decode.sh
echo "openssl enc -aes-256-cbc -d < 177343.tar.e | tar x" >> decode.sh
sendEmail -f $SENDER -t $EMAIL -u "$b - Finished" -m "See Attached" -a "decode.sh" -s smtp.gmail.com -o tls=yes -xu $SENDER -xp $PASSWD
rm -rf 177343
#Remember the first question?