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