#/bin/sh # This script monitors if a dvb device's frontend is opened by VDR. # Can be used with a single tuner or with two tuners. # Output: # 1 - adapter 0 is on # 2 - adapter 1 is on # 3 - both are on # - - both are off # . - VDR is not running # VDR executable. Change to vdr.bin for OpenELEC. VDR=vdr # Uncomment this if you want to output timestamps of status changes PRINT_TIMESTAMPS=yes old_status='*' old_stamp=$(date +%s) while true; do vdrpid=$(pidof $VDR) if [ -z "$vdrpid" ]; then status='.' else mask=0 for adapter in 0 1; do if lsof -p $vdrpid 2>/dev/null | grep -q "adapter$adapter/frontend"; then mask=$(($mask + $adapter + 1)) fi done if [ $mask -eq 0 ]; then status='-' else status=$mask fi fi stamp=$(date +%s) if [ -n "$PRINT_TIMESTAMPS" -a "$old_status" != "$status" ]; then printf '\n[%s] %s>%s +%ds\n' $(date +%H:%M:%S) "$old_status" $status $(($stamp - $old_stamp)) old_stamp=$stamp fi old_status=$status printf "$status" sleep 1 done