Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Conditional Bug?
- X-seq: zsh-users 12130
- From: jadamson@xxxxxxxxxxxx (Joel J. Adamson)
- To: zsh-users@xxxxxxxxxx
- Subject: Conditional Bug?
- Date: Mon, 29 Oct 2007 10:49:20 -0400
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
Howdy zshers,
I'm using I have the following script to backup my important files, and I've
been running it from cron and getting errors from the tar command.
I'm concerned about the conditional at line 22: is my usage wrong or
is this a bug? The conditional says that the file exists (when it
does not) and therefore runs the "--update" version of tar.
Traced invocation from shell prompt ("joel@W0053328:~% " is my prompt):
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
joel@W0053328:~% zsh --version
zsh 4.3.2 (i486-slackware-linux-gnu)
joel@W0053328:~% /home/joel/bin/backup -t /mnt/backup/backup.tar.bz2 ~/ado ~/data ~/docs ~/svn_repo ~/Mail ~/News ~/lisp ~/office-directory ~/.emacs ~/.emacs-custom.el
+/home/joel/bin/backup:37> FILE=''
+/home/joel/bin/backup:38> getopts t: opt
+/home/joel/bin/backup:40> case t (t)
+/home/joel/bin/backup:41> export 'FILE=/mnt/backup/backup.tar.bz2'
+/home/joel/bin/backup:38> getopts t: opt
+/home/joel/bin/backup:47> shift 2
+/home/joel/bin/backup:48> export 'TOBACKUP=/home/joel/ado /home/joel/data /home/joel/docs /home/joel/svn_repo /home/joel/Mail /home/joel/News /home/joel/lisp /home/joel/office-directory /home/joel/.emacs /home/joel/.emacs-custom.el'
+/home/joel/bin/backup:51> [[+/home/joel/bin/backup:1> grep -e backup /etc/mtab
+/home/joel/bin/backup:51> [[ -z '' ]]
+/home/joel/bin/backup:52> mount /dev/backup
+/home/joel/bin/backup:55> backup /mnt/backup/backup.tar.bz2 '/home/joel/ado /home/joel/data /home/joel/docs /home/joel/svn_repo /home/joel/Mail /home/joel/News /home/joel/lisp /home/joel/office-directory /home/joel/.emacs /home/joel/.emacs-custom.el'
+backup:2> export 'FILE=/mnt/backup/backup.tar.bz2'
+backup:3> shift
+backup:4> export 'TOBACKUP=/home/joel/ado /home/joel/data /home/joel/docs /home/joel/svn_repo /home/joel/Mail /home/joel/News /home/joel/lisp /home/joel/office-directory /home/joel/.emacs /home/joel/.emacs-custom.el'
+backup:7> [[ -e /mnt/backup/backup.tar.bz2 ]]
+backup:9> bunzip2 /mnt/backup/backup.tar.bz2
+backup:11> tar --update -f /mnt/backup/backup.tar '/home/joel/ado /home/joel/data /home/joel/docs /home/joel/svn_repo /home/joel/Mail /home/joel/News /home/joel/lisp /home/joel/office-directory /home/joel/.emacs /home/joel/.emacs-custom.el'
tar: Removing leading `/' from member names
tar: /home/joel/ado /home/joel/data /home/joel/docs /home/joel/svn_repo /home/joel/Mail /home/joel/News /home/joel/lisp /home/joel/office-directory /home/joel/.emacs /home/joel/.emacs-custom.el: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
+backup:17> bzip2 -9 /mnt/backup/backup.tar
+/home/joel/bin/backup:56> umount /dev/backup
+/home/joel/bin/backup:57> exit 0
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Here's the script:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#! /bin/zsh -x
# shell script to back up important documents
# should put in cron for 02:00 every night
# 16/10/2007 - h.11:39
# example syntax:
# backup -t /mnt/backup/backup_jja.tbz2 ~/docs ~/data ~/ado ~/bin ~/lisp \
# ~/svn-repo
# pseudocode in comments
# for now, backup device is /dev/backup; this could be a link to
# another device if the user so desires
# backup function (archive file, directories to back up)
backup() {
# 0. parse arguments: first arg is filename, rest are directories to back up
export FILE=$1;
shift;
export TOBACKUP="$*";
# 1. unzip the archive file in its current location (bunzip2)
# test to see if the file exists
if [[ -e $FILE ]]; then
# yes -- unzip it
bunzip2 $FILE
# 2 . update the archive with the listed files
tar --update -f ${FILE/.bz2} $TOBACKUP
else
# no
tar -cvf ${FILE/.bz2} $TOBACKUP
fi
# 3. bzip2 it back up
bzip2 -9 ${FILE/.bz2}
# done
}
# parse commands
FILE=
while getopts t: opt
do
case $opt in
t) export FILE=$OPTARG;;
'?') echo "$0: Please supply the name of a backup file" >&2
exit 1;;
esac
done
shift $((OPTIND - 1))
export TOBACKUP="$*"
# is the backup disk mounted?
if [[ -z `grep -e "backup" /etc/mtab` ]]; then # not mounted
mount /dev/backup
fi
backup $FILE $TOBACKUP || exit 1
umount /dev/backup
exit $?
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Thanks,
Joel
--
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA 02114
(617) 643-1432
(303) 880-3109
The information transmitted in this electronic communication is intended only for the person or entity to whom it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this information in error, please contact the Compliance HelpLine at 800-856-1983 and properly dispose of this information.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author