Is there a means of checking whether the server is currently streaming content from the command line? I’m trying to automate library backup but don’t want the process to start if someone is streaming. None of the logs I’ve examined have obvious playback status indicators.
You should be able to get what you want by looking at this script:
1 Like
That worked great, thanks! I had one minor tweak: It should be calling bash and not sh based on the array usage.
1 Like
Here’s the code I used:
#!/usr/bin/env bash
PMS_IP='TBD'
TOKEN='TBD'
CLIENT_IDENT='SomeRandomStringWithoutSpace'
#Start by getting the active sessions
sessionURL="http://$PMS_IP:32400/status/sessions?X-Plex-Client-Identifier=$CLIENT_IDENT&X-Plex-Token=$TOKEN"
response=$(curl -i -k -L -s $sessionURL)
sessions=$(printf %s "$response"| grep '^<Session*'| awk -F= '$1=="id"{print $2}' RS=' '| cut -d '"' -f 2)
# Active sessions id's now stored in sessions variable, so convert to an array
set -f # avoid globbing (expansion of *).
array=(${sessions//:/ })
if [ $1 == "--num" ]; then
# Just print the number if calling from a script
echo "${#array[@]}"
else
echo "${#array[@]} active streams"
for i in "${!array[@]}"
do
echo "${array[i]}"
done
fi
That’s OS Distro dependent ![]()
1 Like
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.