I am getting this error when I run my Bash script:
syntax error: unexpected end of file
Cant really find where the error is, been looking for hours and still get this error.
Here is the script hope some one cant point me in the right direction:
#!/bin/bash
BACKUPDIR=~/backup
SCRIPTDIR=~/respaldar
BACKUPFILE=/respaldo.$(date +%F).bz2
BACKUPHOST=199.21.112.70
COUNT=$(ls $BACKUPDIR | wc -l)
TRESHOLD=7
if [[ ! -e $BACKUPDIR ]]
then
echo "Creating Backup Directory because it doesn\'t exist !"
mkdir ~/backup
COUNT=0
# exit 0
else
COUNT=$(ls $BACKUPDIR | wc -l)
fi
if [[ $COUNT -le $THRESHOLD ]]
then
tar -cjvf $BACKUPDIR/$BACKUPFILE $SCRIPTDIR
if [[ $? -ne 0 ]]; then echo "Problems Creating Backup File;" fi
scp $BACKUPDIR/$BACKUPFILE $BACKUPHOST:
if [[ $? -ne 0 ]]; then echo "Problems Copying Backup File to Backup Host;" fi
fi
#END
Appreciate the help.
I copyed the whole stuff to vi and it spotted the same thing as fedorqui
:
if [[ $? -ne 0 ]]; then echo "Problems Creating Backup File;" fi
...
if [[ $? -ne 0 ]]; then echo "Problems Copying Backup File to Backup Host;" fi
The ;
is before "
and should be after.
I would suggest to use a shorter solution in both cases:
[ $? -ne 0 ] && echo "Problems Creating Backup File">&2 && exit 1
This will exit if tar fails. Or even the more talkative version:
tar -cjvf $BACKUPDIR/$BACKUPFILE $SCRIPTDIR || \
{ echo "Problems Creating Backup File">&2;exit 1;}
Or if You want to see an error message only if the whole process fails:
tar -cjvf $BACKUPDIR/$BACKUPFILE $SCRIPTDIR && \
scp $BACKUPDIR/$BACKUPFILE $BACKUPHOST: || \
{ echo "Backup failed">&2;exit 1;}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.