diff options
Diffstat (limited to 'abs/core/linhes-scripts/idle.sh')
-rwxr-xr-x | abs/core/linhes-scripts/idle.sh | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/abs/core/linhes-scripts/idle.sh b/abs/core/linhes-scripts/idle.sh index 70db6f0..7733b27 100755 --- a/abs/core/linhes-scripts/idle.sh +++ b/abs/core/linhes-scripts/idle.sh @@ -1,12 +1,14 @@ #!/bin/bash usage () { - echo "Usage: $0 [-h] [-s] [-t <minutes_needed>] [-l] [-v]" + echo "Usage: $0 [-h] [-s] [-t <minutes_needed>] [-l] [-w] [-d] [-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 "-v - Be more verbose for debugging" echo echo "Silent mode is recommended for use in cron jobs or scripts." @@ -24,15 +26,19 @@ mysql_cmd () { # Command line argument handling VERBOSE=1 LOGINS=0 +WINDOWS=0 +DAILY=0 TIME_BEFORE=20 TIME_AFTER=5 # Only adjustable by editing here -while getopts "hslt:v" OPT ; do +while getopts "hslwdt: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 ;; v) VERBOSE=2 ;; *) usage 1 ;; esac @@ -41,14 +47,17 @@ done shift $(($OPTIND - 1)) [ -n "$*" ] && usage 1 -msg "Checking what MythTV is doing now or plans within $TIME_BEFORE minutes..." +msg "Checking what MythTV is doing now or plans to within $TIME_BEFORE minutes..." msg /usr/bin/mythshutdown -s 1 BUSY="$?" msg "mythshutdown returned $BUSY" -# Ignore certain non-zero flag values -BUSY=$(($BUSY & 0x2F)) +if [ "$DAILY" -eq 0 ] ; then + msg " including daily wake (64) as system idle" + # Ignore certain non-zero flag values + BUSY=$(($BUSY & 0x2F)) +fi SCHEMALOCK=$(mysql_cmd "select count(*) from schemalock") msg "schemalock $SCHEMALOCK" @@ -95,24 +104,54 @@ if [ "$VERBOSE" -ge 2 ] ; then }' fi +# Check all frontends if they are playing +HOSTNAMES=$(mysql_cmd "select hostname from settings where value = 'FrontendIdleTimeout'") +PLAYING=0 +for HOST in $HOSTNAMES +do + if [ "$VERBOSE" -ge 2 ]; then + msg "Checking if $HOST is playing recordings or videos..." + fi +ncOUTPUT=$(nc $HOST 6546 << EOF +query location +quit +EOF +) + if [[ "$ncOUTPUT" == *"# Playback "* ]]; then + PLAYING=$(( $PLAYING + 1 )) + msg "$HOST is playing a recording or video" + else + msg "$HOST is NOT playing a recording or video" + fi +done + +# Check for users logged in if [ "$LOGINS" -ge 1 ] ; then USERS=`/usr/bin/last | /bin/grep "still logged in" | awk '{ print $1 }'` if [ -n "$USERS" ] ; then LOGINS=1 - msg "The following user(s) are still logged in: ${USERS}" + msg "The following user(s) are still logged in:" + msg "${USERS}" else LOGINS=0 - msg "No user(s) are logged in..." + msg "No users are logged in" fi fi # Check for open windows -/usr/LH/bin/xwin_find.sh -q '.*(mythtv@|xterm|Firefox|Namoroka|Opera).*' -WINDOWS="$?" -WINDOWS=$(($WINDOWS == 0)) -msg "windows $WINDOWS" +FOUNDWINDOWS=0 +if [ "$WINDOWS" -ge 1 ] ; then + /usr/LH/bin/xwin_find.sh -q '.*(mythtv@|xterm|Firefox|Namoroka|Opera|Chromium).*' + FOUNDWINDOWS="$?" + FOUNDWINDOWS=$(($FOUNDWINDOWS == 0)) + if [ "$FOUNDWINDOWS" -eq 0 ] ; then + msg "no application windows open" + else + msg "one or more application windows open" + fi +fi -activities=$(($BUSY + $SCHEMALOCK + $JOBS + $INUSE + $UPCOMING + $LOGINS + $WINDOWS)) +activities=$(($BUSY + $SCHEMALOCK + $JOBS + $INUSE + $UPCOMING + $PLAYING + $LOGINS + $FOUNDWINDOWS)) msg if [ "$activities" -eq 0 ] ; then msg "System is idle" |