0

I am writing a backup script. I think my syntax is correct but it still gives me an error.

Here's my script:

if [ ! -f $LIST ]; then
    /usr/bin/tar -g $FULLLIST -zpcf $FULL $TGT
    cp $FULLLIST $DIFFLIST
    expect << EOF
    spawn /usr/bin/scp $FULL $HOST:$DST
    expect "password:"
    send "blahblah\r"
    expect eof
    EOF
    rm $FULL
elif [ $DAY == 01 ]; then
    *same as above*
elif [ $DAYOFWEEK == 0 ]; then
    *same as above*
else
    *same as above*
fi

The error is

Syntax error: end of file unexpected (expecting "fi")

When I type in "./webbackup.sh"

1 Answers1

2

You incorrectly closed here document. When youw rite:

expect <<EOF

The line has to be exactly EOF. No spaces before and after it. Exactly EOF. You want:

    expect << EOF
    spawn ...
^^^^ - these spaces are "preserved"
EOF
   ^ also no spaces after!

You can use -<delimiter> and then it will ignore leading tabs. Not spaces.

    expect <<-EOF
    spawn /usr/bin/scp $FULL $HOST:$DST
    ...
    EOF
^^^^ - this is a tab character

Research a here-document in shell.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111