bash Torrent下载完成后传输不会执行shell脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26304521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:31:31  来源:igfitidea点击:

Transmission will not execute shell script after completion of torrent download

linuxbashshellubuntubittorrent

提问by beatsforthemind

I am looking to have the Transmission bittorrent client execute a script that changes the owner and permissions of all torrents in the completed folder when a torrent completes downloading.

我希望让传输 bittorrent 客户端执行一个脚本,该脚本在种子下载完成时更改已完成文件夹中所有种子的所有者和权限。

I am using the following relevant settings in /etc/transmission-daemon/settings.json:

我在 /etc/transmission-daemon/settings.json 中使用以下相关设置:

"download-dir": "/data/transmission/completed",
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/home/user/script.sh",

The script does not seem to be executing after a torrent completes, I know there are other issues that could be going on aside the from the content of the script itself. The owner of the script file is debian-transmission and I have the permissions set to 777, so there shouldn't be an issues with Transmission accessing the script unless I have missed something here.

在 torrent 完成后,脚本似乎没有执行,我知道除了脚本本身的内容之外,还有其他问题可能会发生。脚本文件的所有者是 debian-transmission 并且我的权限设置为 777,因此除非我在这里遗漏了某些内容,否则传输访问脚本应该不会出现问题。

The /home/user/script.sh file is as follows:

/home/user/script.sh 文件如下:

#!/bin/bash
echo sudopassword | /usr/bin/sudo -S /bin/chmod -f -R 777 /data/transmission/completed
echo sudopassword | /usr/bin/sudo -S /bin/chown -f -R user /data/transmission/completed

I know it is poor form to use a sudo command in this fashion, but I can execute the script on it's own and it will work correctly. I am not sure why Transmission is not executing the script. Transmission supports some environment variables such as TR_TORRENT_NAME that I would like to use once the script is being triggered. Is there anything I am not setting up in the file that would prevent the script from working correctly and how would I use environment variables?

我知道以这种方式使用 sudo 命令是一种糟糕的形式,但我可以自己执行脚本并且它会正常工作。我不确定为什么传输不执行脚本。传输支持一些环境变量,例如 TR_TORRENT_NAME,我想在脚本被触发后使用它们。有什么我没有在文件中设置的东西会阻止脚本正常工作,我将如何使用环境变量?

Any help would be greatly appreciated!

任何帮助将不胜感激!

回答by Stef

Add the userwho will execute the script to a groupwith default sudoaccess.


Fedora- add user to the wheelgroup

将执行脚本的用户添加到具有默认sudo访问权限的组中


Fedora- 将用户添加到wheel

sudo usermod -aG wheel $(whoami)

sudo usermod -aG wheel $(whoami)

Ubuntu- user group: sudoor admin(deprecated)