Search code examples
wordpressmacosbashshellrsync

'rsync' bash script help for file synchronisation to wordpress live server


I have a bash script that I want to use to synchronise the local changes I made to my wordpress site using the rsync command. However, when I try to run the file in the command line, it only displays the contents of the file?

The script:

#!/bin/bash

echo "Deploying website”

SOURCE_DIR=“/my/local/path/to/files”
TARGET_DIR="/remote/dir/location"
TARGET_SERVER=“user@server -pPORT”

echo "Synchronising"
echo ""

# rsync to live server
rsync --progress --exclude ‘wp-config.php’ --stats --archive -z --compress --delete -t $SOURCE_DIR $TARGET_SERVER:$TARGET_DIR

echo ""
echo "Done”

As I said, when executing: sh ./sync.sh in the command line, it only displays the contents of the script.

Can anyone spot where I'm going wrong? (Obviously, I change the path names and server in real file)

I've set the permissions to 755 and running on OSX

Any help would be greatly appreciated, thanks.


Solution

  • Unless it is just a copying error, you seem to have the wrong sort of double -quote at the end of the first echo (" at start doesnt match ” at end). This means the string parameter to echo goes on to the next ("), then continues with the next (") and so on until the whole file is echoed.

    Ensure all double and single quotes have not been "magicked" by your editor.