Re: backup script directory errors fixed, now it can't find the eof
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Fri, 29 Aug 2008 18:57:51 +0000
On 2008-08-29, JRough wrote:
I started over with a clean version of the redhat linux backup
script. I found out from "which" that I have tar in /bin/tar. I
don't have any more directory problems. I just put the script in the
root directory and it backs up /home.
I run the script and it finds a premature end of file on line 53?
The :command not founde 21,30,31 are just blank lines. Also on line
18,19, 20 it can't find the date command. If I type in one of the
commands for example date +%a on the command line I get the correct
result. Why is it not finding all these commands? Is it the syntax
error? What could be the syntax error?
Because the date command was not found, the variables $DOW, $DOM
and $DM are empty, and you forgot to quote those variables when you
used them in your tests.
---errors--
backup_new.txt: line 18: date: command not found
backup_new.txt: line 19: date: command not found
backup_new.txt: line 20: date: command not found
: command not founde 21:
: command not founde 30:
: command not founde 31:
backup_new.txt: line 53: syntax error near unexpected token `fi'
---script---
#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@xxxxxxxxxxx>
# and modified by Gerhard Mourani <gmourani@xxxxxxxxxxxx>
#Change the 5 variables below to fit your computer/backup
COMPUTER=sf6h31 # name of this
computer
DIRECTORIES="/home" # directoris to backup
BACKUPDIR=/backups # where to store the
backups
TIMEDIR=/backups/last-full # where to store time of
full backup
TAR=/bin/tar # name and
locaction of tar
#You should not have to change anything below here
PATH=/usr/local/bin:/usr/bin:/bin
It shouldn't matter in this script, but:
export PATH
DOW=`date +%a` # Day of the week e.g. Mon
DOM=`date +%d` # Date of the Month e.g. 27
DM=`date +%d%b` # Date and Month e.g. 27Sep
If the date changes between one invocation of date and the next,
you will have inconsistent dates. Use a singlke call to date
(which is also faster):
eval "$(date +'DOW=%a DOM=%d DM=%d%b' )"
However, I would recommend that you use the ISO date format:
eval "$(date +'DOW=%a DOM=%d DM=%d%b DATE=%Y-%m-%d' )"
# On the 1st of the month a permanet full backup is made
# Every Sunday a full backup is made - overwriting last Sundays backup
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories
# otherwise it backs up files newer than the NEWER date. NEWER
# gets it date from the file written every Sunday.
# Monthly full backup
if [ $DOM = "01" ]; then
You have that backwards; in the shell, the variable needs quoting,
not the literal string:
if [ "$DOM" = 01 ]; then
NEWER=""
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DM.tar $DIRECTORIES
fi
# Weekly full backup
if [ $DOW = "Sun" ]; then
NEWER=""
NOW=`date +%d-%b`
# Update full backup date
echo $NOW > $TIMEDIR/$COMPUTER-full-date
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES
# Make incremental backup - overwrite last weeks
else
# Get date of last full backup
NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`"
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES
fi
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.
- References:
- Prev by Date: Re: '/' become backspace and backspace key insert '~'
- Next by Date: Re: backup script directory errors fixed, now it can't find the eof
- Previous by thread: backup script directory errors fixed, now it can't find the eof
- Next by thread: Re: backup script directory errors fixed, now it can't find the eof
- Index(es):
Relevant Pages
|