#!/bin/sh PRE="preshutdown" # Will allow shutdown only if there is: # no www connection (mythweb or local browser); # no ssh connection; # and mythwelcome running. echo "$PRE: Now is `date --rfc-3339=seconds`" # Check if MythTV would shutdown if mythshutdown --status # If 0 (true), then we need to do few more checks then if netstat -a | grep "tcp" | grep "www" | grep -q "ESTABLISHED" ; then echo "$PRE: exit 1, some active connections to web server. Resetting idle." exit 1 elif netstat -a | grep "tcp" | grep "ssh" | grep -q "ESTABLISHED" ; then echo "$PRE: exit 1, active SSH connection exists. Resetting idle." exit 1 elif ps -C "mythwelcome"; then echo "$PRE: exit 0, mythwelcome is running and no user logged in. MythTV can be suspended." exit 0 else echo "$PRE: exit 1, Unknown reason, resetting idle." exit 1 fi else echo "$PRE: exit 1, mythshutdown --status returned $?, resetting idle." exit 1 fi