Register
It is currently Fri Oct 31, 2014 4:12 pm

email encrypted file chunks


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Aug 02, 2009 2:37 pm   

Joined: Sun Aug 02, 2009 2:30 pm
Posts: 2
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 /?)

Code:
#!/bin/bash
# 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.
SENDER=xxxxxx@gmail.com
PASSWD=xxxxxx
EMAIL=yyyyyyy@gmail.com
# I set this, but I didn't use it correctly.
FILE=./filelist

n=1

# TAR --> ENCRYPT --> GZIP

# Verify directory is correct
echo "$1 will be sent, is this correct(y/n)? \c "
read a

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...
   cd $1
   tar c * -C $1 | openssl enc -aes-256-cbc -e > ~/177343.tar.e
   cd ~
   gzip 177343.tar.e

   # SPLIT, I chose 6M.  177343 is a random directory, I tried
   # to pick something that wouldn't be taken.
   mkdir 177343
   mv 177343.tar.e.gz 177343
   cd 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 "
   read b
   ls -1 |grep x > filelist
   SPLITS=`xargs<filelist`

   filenum=`cat filelist |sed -n '$='`
   echo "$filenum files will be sent to $EMAIL, please wait.."
   cat $FILE |while read line
      do
      {
      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

   #Clean up
   cd ..
   rm -rf 177343
   exit 0

   #Remember the first question?
   else
   exit 0
fi


Last edited by dietbash on Sun Aug 02, 2009 9:22 pm, edited 1 time in total.

Top
 Profile  
 PostPosted: Sun Aug 02, 2009 4:36 pm   

Joined: Sun Aug 02, 2009 2:30 pm
Posts: 2
One thing that I would like to add to this script pertains to the receiving end.

Sometimes I may end up with 10 or more files to download via gmail. Is there a way to download all attachments via bash script? even better.. would be to delete all the files on the pop server once they have been downloaded..

Any ideas? The file attachments are always xaa, xab, xac, etc...


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP