Transmission Cleanup Script running but not working when automated, but runs fine by hand.

Status
Not open for further replies.

gallyjh

Dabbler
Joined
Jun 6, 2018
Messages
28
Hi, I've scoured google and the forums and tried several solutions but none have worked so far. Hoping it's something simple I'm missing.

Here is what the directory of settings.json and script cleanup-torrents.sh looks like:

root@transmission_1:/var/db/transmission # ls -al
total 94
drwxr-x--- 5 transmission transmission 11 Aug 6 20:43 .
drwxr-xr-x 14 root wheel 18 Jul 22 13:17 ..
drwxrwxrwx 2 transmission transmission 2 Jul 20 13:53 blocklists
-rwxr-xr-x 1 transmission transmission 1248 Aug 6 20:41 cleanup-torrents.sh
-rw------- 1 transmission transmission 688 Aug 6 18:07 dht.dat
drwxrwxrwx 2 transmission transmission 2 Aug 6 20:52 resume
-rw------- 1 transmission transmission 2356 Aug 6 18:07 settings.json
-rw------- 1 transmission transmission 2356 Aug 6 17:37 settings.json.save
-rw------- 1 transmission transmission 150 Aug 6 20:07 stats.json
-rw-r--r-- 1 transmission transmission 163 Aug 6 20:52 test
drwxrwxrwx 2 transmission transmission 2 Aug 6 20:52 torrents


As the title says, when I run my script by hand:

#!/bin/sh

cd /var/db/transmission/

DIR=`pwd`

echo "$DIR"

touch test

# port, username, password
SERVER="--auth ZZZZZ:XXXXX"

WORKING=`transmission-remote $SERVER --list`

# use transmission-remote to get torrent list from transmission-remote list
TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d' -e '$d' | awk '{print $1}' | sed -e 's/[^0-9]*//g'`

echo $TORRENTLIST >> test
echo $WORKING >> test

# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
INFO=$(transmission-remote $SERVER --torrent $TORRENTID --info)
echo -e "Processing #$TORRENTID - $(echo $INFO | sed -e 's/.*Name: \(.*\) Hash.*/\1/')"

# check if torrent download is completed
DL_COMPLETED=`echo $INFO | grep "Done: 100%"`
# check torrents current state is
STATE_STOPPED=`echo $INFO | grep "State: Seeding\|State: Stopped\|State: Finished\|State: Idle"`

# if the torrent is "Stopped", "Finished", or "Idle after downloading 100%"
if [ "$DL_COMPLETED" ] && [ "$STATE_STOPPED" ]; then
echo "Torrent #$TORRENTID is completed. Removing torrent from list."
transmission-remote $SERVER --torrent $TORRENTID --remove
else
echo "Torrent #$TORRENTID is not completed. Ignoring."
fi
done


I get my expected results:

root@transmission_1:/var/db/transmission # ./cleanup-torrents.sh
/var/db/transmission
Processing #7 - My torrent test
Torrent #7 is completed. Removing torrent from list.
localhost:9091/transmission/rpc/ responded: "success"


I've updated the following lines in the settings.json file:

"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/var/db/transmission/cleanup-torrents.sh",


Now, of course, I stopped the transmission service first, then updated the settings, then restarted the service. As you can see, I've thrown some debug statements in to see what might be happening. What I've discovered is the script is being ran, because a "test" file is being created by the touch command. I however get two blank carriage returns in the "test" file where I echo those commands in.

Whereas by hand I get the following in the "test" file:

root@transmission_1:/var/db/transmission # cat test
7
ID Done Have ETA Up Down Ratio Status Name 7 100% 1.74 MB Done 0.0 0.0 0.0 Idle NCH Debut Video Capture Software v2 02 incl Keygen-LAXiTY Sum: 1.74 MB 0.0 0.0


Which made me think it's a permission problem with the command transmission-remote, so I checked the permissions on that:

root@transmission_1:/var/db/transmission # ls -al /usr/pbi/transmission-amd64/bin/
total 967
drwxr-xr-x 2 root wheel 30 Mar 10 20:27 .
drwxr-xr-x 17 root wheel 27 Jul 20 13:09 ..
lrwxr-xr-x 1 root wheel 8 Jun 27 2015 2to3-2 -> 2to3-2.7
-rwxr-xr-x 1 root wheel 118 Jun 27 2015 2to3-2.7
-rwxr-xr-x 1 root wheel 167072 Feb 26 2016 curl
-r-xr-xr-x 1 root wheel 6479 Feb 26 2016 curl-config
-r-xr-xr-x 1 root wheel 15656 Dec 9 2014 dht-example
-rwxr-xr-x 1 root wheel 150 Jun 27 2015 django-admin.py
-rwxr-xr-x 1 root wheel 346 Jun 27 2015 easy_install
-rwxr-xr-x 1 root wheel 354 Jun 27 2015 easy_install-2.7
-r-xr-xr-x 1 root wheel 55456 Dec 9 2014 event_rpcgen.py
-rwxr-xr-x 1 root wheel 153 Dec 9 2014 external-ip
-r-xr-xr-x 1 root wheel 25512 Dec 9 2014 iconv
lrwxr-xr-x 1 root wheel 7 Jun 27 2015 idle2 -> idle2.7
-rwxr-xr-x 1 root wheel 116 Jun 27 2015 idle2.7
-rwxr-xr-x 1 root wheel 8888 Dec 9 2014 indexinfo
-rwxr-xr-x 1 root wheel 9624 Dec 9 2014 natpmpc
lrwxr-xr-x 1 root wheel 8 Jun 27 2015 pydoc2 -> pydoc2.7
-rwxr-xr-x 1 root wheel 101 Jun 27 2015 pydoc2.7
lrwxr-xr-x 1 root wheel 9 Jun 27 2015 python2 -> python2.7
lrwxr-xr-x 1 root wheel 16 Jun 27 2015 python2-config -> python2.7-config
-r-xr-xr-x 1 root wheel 5176 Jun 27 2015 python2.7
-r-xr-xr-x 1 root wheel 1704 Jun 27 2015 python2.7-config
-rwxr-xr-x 1 root wheel 70136 Jan 31 2015 sqlite3
-r-xr-xr-x 1 root wheel 427376 Mar 10 20:27 transmission-daemon
-r-xr-xr-x 1 root wheel 448472 Mar 10 20:27 transmission-remote
-rwxr-xr-x 1 root wheel 23552 Dec 9 2014 upnpc
-r-xr-xr-x 1 root wheel 12656 Feb 1 2015 utp_recv
-r-xr-xr-x 1 root wheel 13656 Feb 1 2015 utp_send
-r-xr-xr-x 1 root wheel 15720 Feb 1 2015 utp_test


I tried changing the owner to transmission:transmission for tranmission-remote, but that didn't help. So I put that back to root:wheel.

Here is the output of ps -aux, in case that may hint towards something:

root@transmission_1:/var/db/transmission # ps -aux
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 11345 0.0 0.0 20448 5044 - SsJ 16:39 51:18.96 /usr/local/sbin/openvpn --cd /usr/local/etc/openvpn --daemon openvpn --config /usr/local/etc/openvpn/openvpn.conf --writepid /var/run/ope
root 64783 0.0 0.1 145036 49416 - SJ 15:36 0:08.62 /usr/pbi/transmission-amd64/bin/python2.7 /usr/pbi/transmission-amd64/control.py start 192.168.86.29 12349
root 64853 0.0 0.0 10464 2072 - SsJ 15:36 0:02.24 /usr/sbin/syslogd -s
root 64947 0.0 0.0 55676 5892 - IsJ 15:36 0:00.02 /usr/sbin/sshd
root 64951 0.0 0.0 12564 2008 - IsJ 15:36 0:00.06 /usr/sbin/cron -s
root 76061 0.0 0.0 83092 6624 - SsJ 18:06 0:00.55 sshd: root@pts/0 (sshd)
transmission 76867 0.0 0.1 105968 27400 - SsJ 18:07 22:53.91 /usr/pbi/transmission-amd64/bin/transmission-daemon -g /var/db/transmission -x /var/run/transmission/daemon.pid
root 1345 0.0 0.0 21164 2104 0 R+J 20:59 0:00.00 ps -aux
root 76064 0.0 0.0 19600 3372 0 SsJ 18:06 0:00.29 -csh (csh)


Any suggestions on this?
 

anmnz

Patron
Joined
Feb 17, 2018
Messages
286
Your script assumes that "transmission-remote" is available on PATH. Perhaps it will work better if you explicitly add the appropriate directory to PATH at the start of the script, like this.
Code:
PATH=/usr/pbi/transmission-amd64/bin:$PATH
 

gallyjh

Dabbler
Joined
Jun 6, 2018
Messages
28
Good suggestion and it looked promising. Unfortunately it didn't work. I updated the script like so:

#!/bin/sh

cd /var/db/transmission/

rm test

touch test

DIR=`pwd`

echo $DIR >> test

echo $PATH >> test

PATH=/usr/pbi/transmission-amd64/bin:$PATH

echo $PATH >> test

# port, username, password
SERVER="--auth XXXX:XXXX"

WORKING=`transmission-remote $SERVER --list`

# use transmission-remote to get torrent list from transmission-remote list
TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d' -e '$d' | awk '{print $1}' | sed -e 's/[^0-9]*//g'`

echo $TORRENTLIST >> test
echo $WORKING >> test

# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
INFO=$(transmission-remote $SERVER --torrent $TORRENTID --info)
echo -e "Processing #$TORRENTID - $(echo $INFO | sed -e 's/.*Name: \(.*\) Hash.*/\1/')"

# check if torrent download is completed
DL_COMPLETED=`echo $INFO | grep "Done: 100%"`
# check torrents current state is
STATE_STOPPED=`echo $INFO | grep "State: Seeding\|State: Stopped\|State: Finished\|State: Idle"`

# if the torrent is "Stopped", "Finished", or "Idle after downloading 100%"
if [ "$DL_COMPLETED" ] && [ "$STATE_STOPPED" ]; then
echo "Torrent #$TORRENTID is completed. Removing torrent from list."
transmission-remote $SERVER --torrent $TORRENTID --remove
else
echo "Torrent #$TORRENTID is not completed. Ignoring."
fi
done


The output I received:

root@transmission_1:/var/db/transmission # cat test
/var/db/transmission
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin://bin
/usr/pbi/transmission-amd64/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin://bin




So the path does get updated, and we still see the empty string returns by the command. If it didn't see the command, I'd expect at least expect a "transmission-remote: command not found" reply, no? Any other advice is appreciated.
 

anmnz

Patron
Joined
Feb 17, 2018
Messages
286
I don't know how exactly you are running the script "when automated", but it occurs to me that maybe you are losing error messages that are being printed to stderr rather than stdout. One way to check this is to redirect stderr to stdout. You could perhaps add 2>&1 at the end of the commands you are running inside backticks, for example:
Code:
WORKING=`transmission-remote $SERVER --list 2>&1`
Or you could put
Code:
exec 2>&1
as one of the first lines of the script. This will tend to break the functioning of your script as it will start reading error messages as if they were the normal output of commands, but as a temporary hack it might help check if you're losing error messages that way.
 

gallyjh

Dabbler
Joined
Jun 6, 2018
Messages
28
That was my thought exactly. So I followed the post here:
https://serverfault.com/a/103569/104167

So I threw in:

exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>log.out 2>&1


right after the #!/bin/sh

Even more bizarre, now nothing is output in the log.out or test. However it does output to both if I run by hand.

In regards to how I'm running the script, I'm doing it through tranmissions's builtin ability to execute a script after a download is complete. This is set in their settings.json file. I've outlined that in the OP, if you are interested.
 

gallyjh

Dabbler
Joined
Jun 6, 2018
Messages
28
Interesting enough, I reverted those lines, and threw in your statement and got this in the test file:


[2018-08-07 07:47:47.084] transmission-remote: (http://localhost:9091/transmission/rpc/) Failure when receiving data from the peer


Not sure what to make of it...

Could it be having communication issues with "localhost", maybe i should specify the ip instead?

[EDIT]
Threw in the IP, didn't work. Only got this:

[2018-08-07 07:52:18.887] transmission-remote: (http://192.168.86.29:9091/transmission/rpc/) Failure when receiving data from the peer
 

gallyjh

Dabbler
Joined
Jun 6, 2018
Messages
28
This "Failure when receiving data from the peer" is apparently a CURL issue. Going to add some CURL calls to see what the results are there...

[EDIT]

Threw in a

CURLTEST=`curl icanhazip.com 2>&1`

echo $CURLTEST >> test


And got:

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 curl: (52) Empty reply from serveral Spent Left Speed


Seems like some kind of network issue with CURL for sure, just not sure why the transmission user can't seem to access anything internally or externally...

Anyone seen this?
 
Last edited:
Status
Not open for further replies.
Top