Register
It is currently Wed Sep 17, 2014 9:39 pm

cbz2 : my Backup Script ( xdialog and mutt )


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 

Was is useful to you?
Poll ended at Thu Aug 25, 2005 9:43 am
yes 0%  0%  [ 0 ]
no 0%  0%  [ 0 ]
Dont know 0%  0%  [ 0 ]
Total votes : 0
Author Message
 PostPosted: Fri May 27, 2005 9:43 am   
User avatar

Joined: Wed May 18, 2005 5:32 am
Posts: 4
Location: Australia
This is my Backup script,;
It requires xdialog, mutt and bash.
Its working.
I wish to have some comments about my code.
Is there any way I could simply simplify part of my code ?

Code:
#!/bin/bash
# Author  : Chitlesh GOORAH
# Copyright (C)2005 Chitlesh GOORAH

# This bash script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# purpose : to backup in tar.bz2 format and send to email
# usage   :    cbz2 <h|v>
#      cbz2 <c|d|l> <directories>

#for one argument only
if [ $# -eq 1 ]; then

case "$1" in

   # help section
   h)   echo "cbz2 usage: cbz2 [c|h|d|l|v] <directories>"
        echo
         ;;
 
   # version section
   v)   echo "cbz2 version 1.2 ( 27 May 2005 )"
      echo "http://spaces.msn.com/members/chitlesh"
        echo "cgoorah@yahoo.com.au"
   echo
         ;;
   
   *)   echo "type: 'cbz2 h' for more information"
       ;;
   
esac

#for more than one argument
elif [ $# -gt 1 ]; then

case "$1" in

   # creating .tar.bz2
   c)   for i in $* ; do

              if [ -d $i ]; then
       file=$PWD/cbz2$$.tar.bz2
       echo "adding $i to $file"       
       tar cjf $file $i
      
       Xdialog --backtitle "Chitlesh File Creation" \
                     --title "Backup Mail Sender" \
                          --radiolist "Choose an email account:" 22 33 5 \
              "X@Y.com"       "" ON  \
               "X@Y.com"       "" off \
              "X@Y.com"       "" off \
         "X@Y.com"       "" off \
           "X@Y.com"       "" off \
                 "chitlesh@gmail.com"   "" off 2>/tmp/checklist.tmp.$$

      retval=$?
      choice=`cat /tmp/checklist.tmp.$$`
      rm -f /tmp/checklist.tmp.$$

      case $retval in
        0)    MAIL=$choice
                  ;;
        1)    rm cbz2$$.txt $file
           exit
                  ;;
        255)  rm cbz2$$.txt $file
           exit
                  ;;
      esac
      
       subject=`date "+%D%T"`
       echo "`date "+%T"` $i "> cbz2$$.txt
       echo "sending $file to $MAIL"
      
       #kmail $MAIL -s $subject --attach $file
       mutt -s $subject -a $file $MAIL < cbz2$$.txt
      
       rm cbz2$$.txt $file
      
       elif [ $i != $1 ];then
       echo "cbz2 usage: cbz2 c <directories>"
          fi
      
        done
   ;;
   
   # decompresseing .tar.bz2
   d)  for i in $* ; do
              if [ -e $i ]; then
              tar xjf $i ||    echo "$i is not in the <archive>.tar.bz2 format"
          elif [ $i != $1 ]; then
       echo "cbz2 usage: cbz2 d <archive>.tar.bz2"
       fi
   done
   ;;
   
   # listing .tar.bz2   
   l)  for i in $* ; do
            if [ -e $i ] ; then
           tar tjf $i ||    echo "$i is not in the <archive>.tar.bz2 format"
       elif [ $i != $1 ]; then
      echo "cbz2 usage: cbz2 l <archive>.tar.bz2"
       fi
   done
   ;;
   
   *)   echo "type: 'cbz2 h' for more information"
      ;;   
   

esac

else
    echo "type: 'cbz2 -h' for more information"
fi

# 27 | 05 | 2005 GNU GPL Licence
#            improved on argument command
# 23 | 05 | 2005 enhancing codes
#    tar xjf $i
#    if [ $? -eq 1 ] ; then
#       echo "$i is not in the <archive>.tar.bz2 format"
#    fi
# 15 | 05 | 2005 enhacing to have more than one receivers
# 14 | 05 | 2005 enhancing command-line mail sender
# 13 | 05 | 2005 Date of creation


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 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