0

I have a rtorrent + rutorrent setup which will move downloaded torrent content to ~/rtorrent/completed using autotools plugin. Inotifywait in background checks any new files that appears on ~/rtorrent/completed then the file will uploaded to google drive using rclone copy

So once the first torrent is finished and then it moves files to above folder and rclone starts uploading, but the issue is when second torrent completes and it moves content to ~/rtorrent/completed again then first uploading process breaks. Inotifywait takes this as a new event. Is there anyway that I can have a queue so it goes one by one?

Here is the shell script that is running.

#!/bin/bash

cd ~/rtorrent/readytoupload/
inotifywait -m ~/rtorrent/readytoupload -s ~/rtorrent/log.txt -e create -e moved_to |
    while read path action file; do
        echo "The file '$file' appeared in directory '$path' via '$action'"
        rclone copy $file tempd:test/$file
    done

1 Answer 1

1

Some years ago I had done a similar process at work. I had a samba share on a linux accepting files and the goal was to move the video files from there to another directory and process them with ffmpeg and then upload it to youtube. I can't post the scripts code since I don't have it at hand anymore (I have switched jobs) but I can give you some hints: you need to send the newly file a pipe (man mkfifo) and a secondary script to "read" the lines from that pipe on a loop.

So you will end up with at least two scripts, one for running inotifywait to send the new filename to the pipe and a secondary script to read the pipe and fire the process you need (in your case, an upload with rclone). Any new file added will be put in the pipe and will wait for the file. The first script must keep watching for new files and send them to the secondary script ASAP.

ie:

#!/bin/bash
cd ~/rtorrent/readytoupload/
inotifywait -m ~/rtorrent/readytoupload -s ~/rtorrent/log.txt -e create -e moved_to |
while read path action file; do
   echo "The file '$file' appeared in directory '$path' via '$action'"
   # I'm not entirely sure about the & placement here, if its neccesary at all,
   # but the goal is to prevent a block while the secondary script is working on another file.
   echo ${file} > /tmp/mypipe &
done

and an example of the seconday script:

#!/bin/bash
while true ; do
    if read line < /tmp/mypipe ; then
        echo $line
        # your rclone command goes here.
    fi
loop

Braces are to prevent filenames with spaces to be interpreted as several parameters. you should quote them like this "${file}".

If you want to fire the script once you start the computer you will need a third script to do the job, I recommend using su -c with the & to fire the daemons scripts from rc.local or whatever similar script is run from (/etc/rc.d or /etc/init.d).

You must log in to answer this question.

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