Rtorrent: Executing script not working as expected

Created on 15 Aug 2016  路  4Comments  路  Source: rakshasa/rtorrent

Hi,
I'm trying to execute a script after torrent is complete.

Here is the script:

#!/usr/bin/env bash
TORRENT_PATH=$1
TORRENT_NAME=$2
TORRENT_LABEL=$3

echo "Calling '$1' '$2' '$3'" >> /shared/scripts/completed.sh.log

http -p hb --form POST http://127.0.0.1:3000/torrent \
        cache-control:no-cache \
        content-type:application/x-www-form-urlencoded \
        path="$TORRENT_PATH" \
        hash="unknown" \
        name="$TORRENT_NAME" >> /shared/scripts/completed.sh.log

Here is the line of my .rtorrent.rc:

system.method.set_key=event.download.finished,filebot_amc,"execute={/shared/scripts/completed.sh,$d.get_base_path=,$d.get_name=,$d.get_custom1=}"

The script is executed but I get this as output:

Calling '/shared/Downloads/sometorrent' 'sometorrent' ''

However when I try to run it from terminal manually:

Calling /shared/Downloads/sometorrent sometorrent
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/plain; charset=utf-8
Content-Length: 2
ETag: W/"2-4KoCHiHd29bYzs7HHpz1ZA"
Date: Mon, 15 Aug 2016 00:20:53 GMT
Connection: keep-alive

OK

it works. Why it doesn't work when running from rtorrent?

Thanks in advance,

PS: I'm sorry if this is the wrong place I am not sure where to post it

Most helpful comment

The better fix is to use "--ignore-stdin".

All 4 comments

This is just a guess, but it sounds like http is sending it's output to stderr and not stdout. Try 2>&1 >> /shared/scripts/completed.sh.log at the end of the command. 2>&1 means "send stderr (2) to stdout (1) instead"

@kannibalox I redirected the output unfortunately it stil doesn't work.

Here are modified files

$ cat completed.sh
#!/usr/bin/env bash
echo 'Locking logs...' >> /shared/scripts/completed.sh.log
bash -c "/shared/scripts/run.sh '$1' '$2' '$3'" >> /shared/scripts/completed.sh.log 2>&1
#!/usr/bin/env bash
TORRENT_PATH=$1
TORRENT_NAME=$2
TORRENT_LABEL=$3

echo "Calling '$1' '$2' '$3'"

python /usr/bin/http -p hb --form POST http://127.0.0.1:3000/torrent cache-control:no-cache content-type:application/x-www-form-urlencoded path="$TORRENT_PATH" hash="unknown" name="$TORRENT_NAME"

And here is a sample output:

Locking logs... # This was executed from rtorrent
Calling '/shared/Downloads/FileA' 'FileA' ''
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
            [--style STYLE] [--print WHAT] [--verbose] [--headers] [--body]
            [--stream] [--output FILE] [--download] [--continue]
            [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
            [--auth USER[:PASS]] [--auth-type {basic,digest}]
            [--proxy PROTOCOL:PROXY_URL] [--follow] [--verify VERIFY]
            [--timeout SECONDS] [--check-status] [--ignore-stdin] [--help]
            [--version] [--traceback] [--debug]
            [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
http: error: Request body (from stdin or a file) and request data (key=value) cannot be mixed.

Locking logs... # Now I'm running this from a terminal manually
Calling '/shared/Downloads/FileA' 'FileA' ''
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/plain; charset=utf-8
Content-Length: 2
ETag: W/"2-4KoCHiHd29bYzs7HHpz1ZA"
Date: Mon, 15 Aug 2016 12:33:41 GMT
Connection: keep-alive

OK

Same arguments, different result. Kinda weird...

Adding < /dev/ttyat the end of script seemed to fix it :)

The better fix is to use "--ignore-stdin".

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lzbk picture lzbk  路  6Comments

nickpeirson picture nickpeirson  路  7Comments

legrostdg picture legrostdg  路  5Comments

MrSorcus picture MrSorcus  路  5Comments

RX14 picture RX14  路  4Comments