Mr Transmission, please turn off the PC after all downloads are completed!
Firstly - stop shutting down with root. Use dbus
.
Next, put something in your script that detects running torrents. Here is a little something that uses trasmission-remote
to count the number of torrents running that aren't "Done":
transmission-remote --list | sed '1d;$d' | grep -v Done | wc -l
To build that into your script:
count=$(transmission-remote --list | sed '1d;$d' | grep -v Done | wc -l)
if [ $count -eq 0 ]; then
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
fi
I'm not a transmission user so my search might be slightly off but this should do the job. You might find that it doesn't shut down all the time if there are some torrents in there that are, for example, paused. If that's the case, play around with the output and a grep -v
clause or two to handle things.
Additionally, you might want a timed shutdown so you're never in a situation where the desktop shuts down while you're on it (so you can abort it). Perhaps just an additional check in there to see what the time is.
Note: transmission-remote
requires you turn on web access to transmission from within its options.
Related videos on Youtube
mini
Updated on September 18, 2022Comments
-
mini over 1 year
#!/bin/bash echo "password" | sudo -S halt
I pointed this script to "Call script when torrent is completed" option under:
Edit > Preferences > Downloading
Problem: this script shut-downs the computer after any finished download while there are more torrents in queue!
How can I improve it?
-
Oli almost 11 yearsOh no, that's horrible @Mitch - it runs transmission as root and would still run into this behaviour (Transmission runs the script when any download finishes - dorfa wants to shutdown after all the downloads have finished)
-
azerafati about 8 years@mini, any update on this matter?
-
-
somoso almost 11 yearsUpvoted for linking to the dbus command. I've learned something new today about Ubuntu!
-
Henning Kockerbeck almost 11 yearsI haven't really looked into that script, but I'd guess it uses Transmissions web client. You can activate that in Transmissions settings. Then make sure the package
php5-cli
is installed to be able to use PHP on the command line. Then you should be able to call the script with something along the lines ofphp /where/you/stored/Transmission_Quit.php --port 9909 --hostname 127.0.0.1 --username my_user --password my_pass
, of course adapted to the path you saved the PHP script to and the settings you chose for the web client. -
mini almost 11 yearsIs it correct if I add
#!/usr/bin/php -q
at the beginning of that php file and renaming.php
to.sh
? (following this instruction) -
Henning Kockerbeck almost 11 yearsYou can, but you don't have to. That line, called a Shebang, tells your computer with which interpreter it should execute the following commands. With it, you execute the script itself and have to make sure it is executable.
php Transmission_Quit.php--port...
means, "call programphp
and let it do what is noted down inTransmission_Quit.php
". In that case, you don't need a Shebang../Transmission_Quit.php --port...
means "call Transmission_Quit.php as a program itself". Here, you do need a Shebang, to tell your computer which language the script is in. It's mostly a matter of taste. -
Vitaly Zdanevich over 10 yearsI tried this command from Terminal: "Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Hal was not provided by any .service files"