2

I run an unRAID server (unRAID is based on Slackware) and would like to find a way to automatically change the permissions and ownership of every file added to a specific directory.

Specifically, I would like to upload .torrent files from my laptop to a specific "Watch" folder on my server using SFTP. The problem is that the rTorrent docker container that is watching that directory is unable to load the uploaded .torrent files because their owner:user group is different from that of the container -- root:root for .torrent files sent via SFTP, and nobody:users for the container.

I suspect that the file permissions may also be an issue as the uploaded .torrent files have 0644 permissions and I believe that they need to have 0755 permissions. I've been able to get rTorrent to autoload these .torrent files by manually chown to nobody:users and chmod to 0755, so I know that Autowatch works with these changes in place.

So, I am hoping that there might be a straightforward way to automatically chown and chmod every file added to this directory. Any ideas?

1

You have another two way to reach your goal with built-in tools

0

This may help: https://techarena51.com/blog/inotify-tools-example/

intotify can allow you to trigger a script when the directory is updated. The script could manage your chown and chmod on the fly.

0

As I mentioned in my comment on SO yesterday, this is fairly trivial using inotify.

#!/bin/sh
if [ -x /tmp/watchy ]; then
  rm -rf /tmp/watchy
fi
while inotifywait  -e close_write -o /tmp/watchy --format %w%f  /path/to/watch
do
  found=$( tail -n1 /tmp/watchy | grep -E '.torrent$' ) && chown root $found
done
  • Thanks a lot. If I wanted the script to both chmod and chown would I modify it like this? #!/bin/sh if [ -x /tmp/watchy ]; then rm -rf /tmp/watchy fi while inotifywait -e moved_to -o /tmp/watchy --format %w%f /mnt/cache/Downloads/watched do found=$( tail -n1 /tmp/watchy | grep -E '.torrent$' ) && chown nobody:users $found && chmod 0755 $found done – xthursdayx Jan 4 at 3:06
  • Yes, that would do the job. – tink Jan 4 at 3:07
  • 1
    I had to change the close_write inotifywait event to create in order to get it to work with the uploaded files, but it's working great now. I also added the script as a "User Script" startup daemon (the unRaid equivalent of adding it to /etc/rc.local) so that it will run in the background all the time, since I quickly realized that the script would stop running as soon as I closed my ssh shell to the headless server. – xthursdayx Jan 4 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.