Page 1 of 1

Completion script to rsync files from seedbox

Posted: Thu May 19, 2011 9:19 am
by Paegus
I've been working on a download completion script that checks if a remote host is online and if so, rsyncs the file over and then marks it for removal from transmission once the seed ratio is reached (by another cron script). Or If the remote host is down it adds the torrent details to a queue file.

My only problem so far is that rsync is a complete pain when dealing with paths that have spaces in them

for example: /home/user/Folder One/folder two/file.or.folder

Code: Select all

rsync -acKPqrze ssh --timeout 30 "$TR_TORRENT_DIR/$TR_TORRENT_NAME" $REMOTEUSER@$REMOTEHOST:"$TR_TORRENT_DIR/$TR_TORRENT_NAME"
sends the file over to /home/$REMOTEUSER/Folder where Folder is the actual file.

Code: Select all

rsync -acKPqrze ssh --timeout 30 "$TR_TORRENT_DIR/$TR_TORRENT_NAME" $REMOTEUSER@$REMOTEHOST:'"$TR_TORRENT_DIR/$TR_TORRENT_NAME"'
sends the file over but then rsync tries to rename it to whatever it's supposed to be called the remote host doesn't know what $TR_TORRENT_DIR and $TR_TORRENT_NAME so tries to rename it to "/" and fails

I've also tried padding $TR_TORRENT_DIR etc with the escape characters or replacing the spaces with ? marks but then rsync interprets them directly as "\ " or "?" and cannot find file "/home/user/Folder\ One/..." or "/home/user/Folder?One/..."

i've trolled around the rsync man-page 'til i'm blue in the fingers and have come up empty.
single & double quotes aren't working unless i don't use a variable. if i type it out manually it works great in both instances.
escaped quotes don't work at all.
question marks for the spaces don't work either

so aside from this not being directly transmission related, any ideas on how to convince rsync to behave?

Re: Completion script to rsync files from seedbox

Posted: Thu May 19, 2011 4:05 pm
by killemov
rsync does not deal with the environment variables itself. Your script environment is probably bad. Take a look at this script and change to your liking. viewtopic.php?f=1&t=10364

Re: Completion script to rsync files from seedbox

Posted: Thu May 19, 2011 5:02 pm
by gunzip

Code: Select all

rsync -acKPqrze ssh --timeout 30 "$TR_TORRENT_DIR/$TR_TORRENT_NAME" $REMOTEUSER@$REMOTEHOST:'"$TR_TORRENT_DIR/$TR_TORRENT_NAME"'
on above, what happens if you just reverse the order of the single and double quotes around the target:

Code: Select all

rsync -acKPqrze ssh --timeout 30 "$TR_TORRENT_DIR/$TR_TORRENT_NAME" $REMOTEUSER@$REMOTEHOST:"'$TR_TORRENT_DIR/$TR_TORRENT_NAME'"
this solves a similar problem for me using scp in ssh so it might work here.

Re: Completion script to rsync files from seedbox

Posted: Fri May 27, 2011 8:26 am
by Paegus
the reason seems to be that anything in single quotes is treated literally... (like so)

so now i just...

Code: Select all

echo "rsync $SYNCARGS "$TR_TORRENT_DIR/$TR_TORRENT_NAME" $REMOTEHOST:'\"$TR_TORRENT_DIR\"'" >> $SYNCTMPFILE
chmod +x $SYNCTMPFILE
$SYNCTMPFILE && goodsyncfunction $TR_TORRENT_ID || badsyncfunction $TR_TORRENT_ID
rm $SYNCTMPFILE
and that seems to work fine... i'll have another look at it if the need arrises but as always, making do works :roll:

thanks anyway.