2

I needed to write a script which syncs multiple directories from local to remote server (bi-directionally).

This script currently uses osync.sh which uses ssh to perform the synchronization. The exact command it uses (which causes my script to fail is located in line 1485 in the osync.sh file on Github):

$SSH_CMD env LC_ALL=C env _REMOTE_TOKEN="$_REMOTE_TOKEN" bash -s << 'ENDSSH' >> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2>&1

This is basically just one ssh command.

We were using rsync for replication, and it did work as intended even with this file path structure. But osync does not.


The problem: The command I need to run is:

osync.sh --initiator="/var/services/homes/@DH-ADS/0/localUser-1/local-folder-to-sync/" --target="ssh://sync-user@DOMAIN:25//var/services/homes/@DH-ADS/0/remoteUser-1/remote-folder-to-sync" --rsakey="/var/services/homes/sync-user/.ssh/id_rsa" --summary --dry --verbose

Where:

  • localUser and remoteUser have the same name (Active Directory /LDAP Username)
  • the sync-user also has the same name on both servers
  • The ssh-key is correct and working.

This command works just fine, if there is no "@" character in the file path. So I think the problem is this character. I cannot change the file path, because it is a Synology Server and this is the default path for Active Directory Users.

The error:

TIME: 0 - This is an unstable dev build [2021062901]. Please use with caution.
TIME: 0 - -------------------------------------------------------------
TIME: 0 - Fri Dec  3 11:34:46 CET 2021 - osync 1.3.0-dev-rc2 script begin.
TIME: 0 - -------------------------------------------------------------
TIME: 0 - Sync task [quicksync_task] launched as sync-user@local-server (PID 22970)
sync-user@REMOTE_DOMAIN (without tld and last character [example.de -> exampl)@REMOTE-SERVER-DOMAIN (correct)'s password: 

As you can see it asks for a password for a user, which I did not specify in any way. And I think the reason is the "@" character in the remote file path (and in the local one maybe too).

I have tried to use '' but then the remote file path and local file path are not found (because it assumes the ' is part of the file path):

osync.sh --initiator="'/var/services/homes/@DH-ADS/0/localUser-1/local-folder-to-sync/'" --target="'ssh://sync-user@DOMAIN:25//var/services/homes/@DH-ADS/0/remoteUser-1/remote-folder-to-sync'" --rsakey="/var/services/homes/sync-user/.ssh/id_rsa" --summary --dry --verbose
TIME: 0 - This is an unstable dev build [2021062901]. Please use with caution.
TIME: 0 - Local replica path [/var/services/homes/@DH-ADS/0/localUser-1/local-folder-to-sync/] does not exist or is not writable and CREATE_DIRS is not allowed.
TIME: 0 - Local replica path ['ssh://video-sync@REMOTE_DOMAIN:25//var/services/homes/@DH-ADS/0/remoteUser-1/remote-folder-to-sync/'/] does not exist or is not writable and CREATE_DIRS is not allowed.
TIME: 0 - _ExecTasksPidsCheck called by [CheckReplicas] finished monitoring pid [22142] with exitcode [1].
TIME: 0 - _ExecTasksPidsCheck called by [CheckReplicas] finished monitoring pid [22143] with exitcode [1].
TIME: 0 - Cancelling task.
TIME: 0 - osync finished with errors.

So is there any way to escape the "@" character in the file path for ssh command? Is the error something else?

I have tested the Write permissions and Create-dirs permissions. Everything is allowed and does work.

I have also tested with the version osync.sh 1.2 (which is latest stable release a few years old) and it also did not work.

1 Answer 1

1

Looking into the source code of the script you linked and digging into the function Init { ... }, yes, the issue is with @ character in your path as that script truncates the shortest suffix from the given path (${parameter%@*} in bellow), so it causes to take wrong remote-userName in:

if [[ "$uri" == *"@"* ]]; then
            # remove everything after '@'
            REMOTE_USER=${uri%@*}

it will end-up to set REMOTE_USER to sync-user@DOMAIN:25//var/services/homes/ which is wrong; script owner could fix this by using longest match stripping ${parameter%%@*} instead;

or modify the osync.sh script that part which I mentioned by yourself, and install again;


Notes:

  1. use only single quotes around that path not both of them like --target='/some/remote/path'.
  2. As I read the script some other parts, it will have issues with = and : characters too if you have them in your paths.
  3. I'm not sure if pointed issue would be the only issue here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .