Re: syntax error in backup script
Jason Pepas wrote:
>
> i am brewing up a backup script, but i am running into an error which
> has me baffled.
>
> i try to run the script and get a syntax error which look something like
> this:
>
> syntax error near unexpected token 'elif'
>
> this is the line in question:
>
> elif [ ! -f "/backup/current/*fullbackup.tar.gz" ]
>
> here is the complete file (sorry, the formatting is mangled (no
> indetions, etc)):
>
[...]
> if [ `date +%A` = "Sunday" && ! -f "/backup/$directoryname" ] then
>
> # if it is sunday and you havent yet done a full backup, do so
>
> fullbackup
>
> elif [ ! -f "/backup/current/*fullbackup.tar.gz" ]
[...]
You need a semicolon after the closing bracket.
>From man sh:
if list; then list; [ elif list; then list; ] ... [ else
list; ] fi
The if list is executed. If its exit status is
zero, the then list is executed. Otherwise, each
elif list is executed in turn, and if its exit sta
tus is zero, the corresponding then list is exe
cuted and the command completes. Otherwise, the
else list is executed, if present. The exit status
is the exit status of the last command executed, or
zero if no condition tested true.
This would change
if [ `date +%A` = "Sunday" && ! -f "/backup/$directoryname" ] then
into
if [ `date +%A` = "Sunday" && ! -f "/backup/$directoryname" ]; then
^
Do the same for the elif part.
HTH
> jason
>
> jason.pepas.com
--
Morgan Terry
mterry@acsbps.com
It is easier to move a problem around (for example, by moving
the problem to a different part of the overall network
architecture) than it is to solve it. --RFC 1925
Reply to: