summaryrefslogtreecommitdiffstats
path: root/abs/core/linhes-scripts/idle.sh
diff options
context:
space:
mode:
Diffstat (limited to 'abs/core/linhes-scripts/idle.sh')
-rwxr-xr-xabs/core/linhes-scripts/idle.sh81
1 files changed, 33 insertions, 48 deletions
diff --git a/abs/core/linhes-scripts/idle.sh b/abs/core/linhes-scripts/idle.sh
index 7733b27..4f6174c 100755
--- a/abs/core/linhes-scripts/idle.sh
+++ b/abs/core/linhes-scripts/idle.sh
@@ -1,14 +1,16 @@
#!/bin/bash
usage () {
- echo "Usage: $0 [-h] [-s] [-t <minutes_needed>] [-l] [-w] [-d] [-v]"
+ echo "Usage: $0 [-h] [-s] [-t <minutes_needed>] [-l] [-w] [-m] [-r] [-v]"
echo
echo "-h - Print this help/usage message and quit"
echo "-s - Run silently (default is verbose)"
echo "-t - Minutes of idle time needed (default is 20)"
echo "-l - Check for user logins (default: false - do not check)"
echo "-w - Check for open windows (default: false - do not check)"
- echo "-d - Include mythshutdown daily wake in system busy (default: daily wake is system idle)"
+ echo "-m - Include mythshutdown daily wake, locked, & about to start wake in system busy"
+ echo " (default: daily wake, locked & about to start wake is system idle)"
+ echo "-r - Check if mythfrontends are running (default: false - do not check)"
echo "-v - Be more verbose for debugging"
echo
echo "Silent mode is recommended for use in cron jobs or scripts."
@@ -28,17 +30,19 @@ VERBOSE=1
LOGINS=0
WINDOWS=0
DAILY=0
+RUNNING=0
TIME_BEFORE=20
TIME_AFTER=5 # Only adjustable by editing here
-while getopts "hslwdt:v" OPT ; do
+while getopts "hslwmrt:v" OPT ; do
case $OPT in
h) usage 0 ;;
s) VERBOSE=0 ;;
t) TIME_BEFORE=$OPTARG ;;
l) LOGINS=1 ;;
w) WINDOWS=1 ;;
- d) DAILY=1 ;;
+ m) DAILY=1 ;;
+ r) RUNNING=1 ;;
v) VERBOSE=2 ;;
*) usage 1 ;;
esac
@@ -50,13 +54,14 @@ shift $(($OPTIND - 1))
msg "Checking what MythTV is doing now or plans to within $TIME_BEFORE minutes..."
msg
-/usr/bin/mythshutdown -s 1
+/usr/bin/mythshutdown --status
BUSY="$?"
msg "mythshutdown returned $BUSY"
if [ "$DAILY" -eq 0 ] ; then
- msg " including daily wake (64) as system idle"
- # Ignore certain non-zero flag values
+ msg " including daily wake, locked, and about to start wake as system idle"
+ # Ignore daily wake, locked and about to start wake flag values
BUSY=$(($BUSY & 0x2F))
+ msg " mythshutdown returned $BUSY"
fi
SCHEMALOCK=$(mysql_cmd "select count(*) from schemalock")
@@ -68,60 +73,40 @@ msg "running jobs $JOBS"
INUSE=$(mysql_cmd "select count(*) from inuseprograms")
msg "inuse programs $INUSE"
-POTENTIAL=$(mysql_cmd "select count(*) from recordmatch as rm, program as p
- where rm.chanid = p.chanid and rm.starttime = p.starttime
- and rm.starttime < now() + interval $TIME_BEFORE minute
- and now() < p.endtime + interval $TIME_AFTER minute")
-msg "potential recordings $POTENTIAL"
-# See if any of the potential upcoming recordings are real.
-# This is ugly, but only the backend knows what programs it really
-# plans to record or ignore, so we can't just check the DB. :-(
-if [ "$VERBOSE" -ge 2 ] ; then
- mysql_cmd "select p.starttime, p.endtime, p.title, subtitle
- from recordmatch as rm, program as p
- where rm.chanid = p.chanid and rm.starttime = p.starttime
- and rm.starttime < now() + interval $TIME_BEFORE minute
- and now() < p.endtime + interval $TIME_AFTER minute
- order by p.starttime, p.endtime"
-fi
-UPCOMING=$(/usr/bin/mythbackend --printsched 2>&1 |
- /bin/awk -v potential=$POTENTIAL '
- BEGIN {item=-1;real=0}
- /--- print list start ---/,/--- print list end ---/ {
- if (item>0 && item<=potential && substr($0,70,1) ~ "[0-9]") real+=1;
- item += 1;
- }
- END {print real}
-')
+UPCOMING=$(timeout 3 misc_upcoming_recordings.pl --plain_text --text_format "%rs " --heading "" --minutes $TIME_BEFORE --recordings -1 | wc -w)
msg "planned recordings $UPCOMING"
if [ "$VERBOSE" -ge 2 ] ; then
- /usr/bin/mythbackend --printsched 2>&1 |
- /bin/awk -v potential=$POTENTIAL '
- BEGIN {item=-1}
- /--- print list start ---/,/--- print list end ---/ {
- if (item>0 && item<=potential) print $0;
- item += 1;
- }'
+ msg
+ timeout 3 /usr/LH/bin/misc_upcoming_recordings.pl --plain_text --minutes $TIME_BEFORE --recordings -1
fi
-# Check all frontends if they are playing
+# Check all host's mythfrontends if they are running and playing
HOSTNAMES=$(mysql_cmd "select hostname from settings where value = 'FrontendIdleTimeout'")
+FERUNNING=0
PLAYING=0
for HOST in $HOSTNAMES
do
if [ "$VERBOSE" -ge 2 ]; then
- msg "Checking if $HOST is playing recordings or videos..."
+ msg "Checking $HOST's mythfrontend status..."
fi
-ncOUTPUT=$(nc $HOST 6546 << EOF
+ncOUTPUT=$(timeout 2 nc $HOST 6546 << EOF
query location
quit
EOF
)
+ if [ "$RUNNING" -ge 1 ] ; then
+ if [[ "$ncOUTPUT" == *"# "* ]]; then
+ FERUNNING=$(( $FERUNNING + 1 ))
+ msg "$HOST's mythfrontend is running $FERUNNING"
+ else
+ msg "$HOST's mythfrontend is NOT running $FERUNNING"
+ fi
+ fi
if [[ "$ncOUTPUT" == *"# Playback "* ]]; then
PLAYING=$(( $PLAYING + 1 ))
- msg "$HOST is playing a recording or video"
+ msg "$HOST is playing a recording or video $PLAYING"
else
- msg "$HOST is NOT playing a recording or video"
+ msg "$HOST is NOT playing a recording or video $PLAYING"
fi
done
@@ -134,7 +119,7 @@ if [ "$LOGINS" -ge 1 ] ; then
msg "${USERS}"
else
LOGINS=0
- msg "No users are logged in"
+ msg "No users are logged in $LOGINS"
fi
fi
@@ -145,13 +130,13 @@ if [ "$WINDOWS" -ge 1 ] ; then
FOUNDWINDOWS="$?"
FOUNDWINDOWS=$(($FOUNDWINDOWS == 0))
if [ "$FOUNDWINDOWS" -eq 0 ] ; then
- msg "no application windows open"
+ msg "no application windows open $FOUNDWINDOWS"
else
- msg "one or more application windows open"
+ msg "one or more application windows open $FOUNDWINDOWS"
fi
fi
-activities=$(($BUSY + $SCHEMALOCK + $JOBS + $INUSE + $UPCOMING + $PLAYING + $LOGINS + $FOUNDWINDOWS))
+activities=$(($BUSY + $SCHEMALOCK + $JOBS + $INUSE + $UPCOMING + $FERUNNING + $PLAYING + $LOGINS + $FOUNDWINDOWS))
msg
if [ "$activities" -eq 0 ] ; then
msg "System is idle"