Is there a way to know if transmission-daemon currently active?

I have a laptop that i use as a media station connected to my TV, occasionally i would fall a sleep and forget to shutdown the laptop and that is unwanted behavior. so i use crontabs to shutdown my laptop everyday at 7AM because i am sure that i am always either asleep or not at home then.

However sometimes i am actually downloading something using transmission-daemon and would prefer the laptop not to turn off at that time. Is there a way to check whether transmission daemon is downloading or not? like a file flag by transmission-daemon? i though about scanning the active ports used by transmission-daemon but i figured that there might be a more elegant solution.

0

1 Answer

Sure. The first one is with transmission not active, the second one is.

rinzwind@schijfwereld:~$ ps -ef | grep transmission | grep -v grep
rinzwind@schijfwereld:~$ ps -ef | grep transmission | grep -v grep
rinzwind 10490 1 11 22:04 ? 00:00:00 transmission-gtk

Is there a way to check whether transmission daemon is downloading or not?

Yes. There is an API and here is an old script from 2013 doing a shutdown for a MAC. Requires 1 change:

subprocess.call(['osascript', '-e','tell application "Finder" to shut down'])

needs to be something like this:

subprocess.call(['shutdown', '--now','turn off'])

It assumes you set up the web interface on port 9091


Pre req:

cd ~
virtualenv .transmission_env
source .transmission_env/bin/activate
pip install transmissionrpc
deactivate

and the script:

#!/Users/fots/.transmission_env/bin/python
import subprocess
import transmissionrpc
from transmissionrpc.error import TransmissionError
def main(): all_done = True try: tc = transmissionrpc.Client('localhost', port=9091) for torrent in tc.get_torrents(): if torrent.status == 'downloading': all_done = False break if all_done: subprocess.call(['osascript', '-e', 'tell application "Finder" to shut down']) except TransmissionError: pass
if __name__ == "__main__": main()
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like