0

I am trying to write an rsync script that would take the user inputed path to the source file and send it over to a another user inputed path on the remote machine.

 #!/bin/bash

echo -e "What is the directory on the local machine you want to send"

read sourcedir


SOURCEDIR = :$sourcedir

echo -e "What is the directory on the GPU box you want to send these files over to?"

read destdir

DESTDIR = :$destdir

rsync -avu -e "ssh -p xxxx" $SOURCEDIR $DESTDIR user@remote.computer --progress

When i execute the script i get the following error

-bash: DESTDIR: command not found
building file list ...
rsync: link_stat "/path/to/script/user@remote.computer" failed: No such file or directory (2)
0 files to consider
sent 29 bytes  received 20 bytes  98.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files could not be transferred (code 23) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-51/rsync/main.c(996) [sender=2.6.9]

Would appreciate your advice/suggestions on writing this script correctly.

PS. I have removed some sensitive information from the output, but rest assured the format is consistent with the output from the computer.

Arpit Solanki
  • 9,567
  • 3
  • 41
  • 57
pshah
  • 43
  • 6

1 Answers1

1

The Problem

In bash, assignments work only without spaces around the =:

variable=value      # assign "value" to variable "variable"
variable = value    # call program "variable" with arguments "=" and "value"

To fix your problem, remove the spaces around the =.

Better Solution

Note that special variables (like PDW, RANDOM, ...) in bash are ALL UPPERCASE by convention. When writing scripts, it is recommended to use lowercase variables to prevent accidental name collisions.

The difference between DESTDIR and destdir is not clear by the variable name. DESTDIR is used only once. I think it would be easier and clearer to write

echo ...
read sourcedir
echo ...
read destdir
rsync ... ":$sourcedir" ":$destdir" ...
Socowi
  • 25,550
  • 3
  • 32
  • 54