See if someone is playing a file from terminal

Is it possible to see if someone is currently playing a file from the terminal? I was thinking about monitoring the Cache directory but if a file can be played directly there is no change in there. Would be really helpful for a shutdown script.
Just checking for a connection to pms will not help me, as not all clients seem to close connections if you just send them to the background and forget about them.

Well I kinda found a solution. Using the PMS API you can get the required information.

Could you please let us know how you retrieved the information? - I’m looking into this for similar reasons but never played around with the API before so if you’d be kind enough to point us in the right direction of the calls you used it would be greatly appreciated :slight_smile:

Sure. Sorry I was so brief. I found the current API at

To get the number of videos currently playing I used
MEDIACOUNT=$(wget -q -O- http://192.168.178.35:32400/status/sessions?X-Plex-Token=myPlexToken | xmllint --xpath 'string(//MediaContainer/@size)' -)

Obviously replace IP and port with your pms values. To find your Plex Token refer to
https://support.plex.tv/hc/en-us/articles/204059436-Finding-your-account-token-X-Plex-Token

I am sure using wget or similar tools you can retrieve a lot of information but I did not really look into it any more as I got what I need.

EDIT: I found out about the API after discovering plexWatch. Maybe this is also useful for some cases:

I was looking for this too, and this post along with https://forums.plex.tv/t/now-playing-from-bash/167597 helped me figure this out.

My complete solution is a bash script. It relies on curl and xmllint

Created a script named get-active-streams with the following content:

#! /bin/sh

PLEX_HOST=${PLEX_HOST:-localhost}

PLEX_TOKEN=$(curl -H "Content-Length: 0" -H "X-Plex-Client-Identifier: my-app" -u $PLEX_USERNAME:$PLEX_PASSWORD -X POST https://my.plexapp.com/users/sign_in.xml --silent | xmllint --xpath "/user/authentication-token/text()" -)
curl --silent http://$PLEX_HOST:32400/status/sessions -H "X-Plex-Token: $PLEX_TOKEN" | xmllint --xpath 'string(//MediaContainer/@size)' -

don’t forget to chmod the file with u+x: chmod ./get-active-streams

and the you can run it like this:

PLEX_USERNAME="<username>" PLEX_PASSWORD="<password>" ./get-active-streams

In case you run this remotely you’ll need to also update the PLEX_HOST variable:

PLEX_HOST="<plex hostname/ip>" PLEX_USERNAME="<username>" PLEX_PASSWORD="<password>" ./get-active-streams

Hope this helps out to anyone trying to figure this out.