Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.17 KB | None | 0 0
  1. #/bin/sh
  2.  
  3. # This script monitors if a dvb device's frontend is opened by VDR.
  4. # Can be used with a single tuner or with two tuners.
  5. # Output:
  6. #  1  - adapter 0 is on
  7. #  2  - adapter 1 is on
  8. #  3  - both are on
  9. #  -  - both are off
  10. #  .  - VDR is not running
  11.  
  12. # VDR executable. Change to vdr.bin for OpenELEC.
  13. VDR=vdr
  14.  
  15. # Uncomment this if you want to output timestamps of status changes
  16. PRINT_TIMESTAMPS=yes
  17.  
  18. old_status='*'
  19. old_stamp=$(date +%s)
  20. while true; do
  21.     vdrpid=$(pidof $VDR)
  22.     if [ -z "$vdrpid" ]; then
  23.         status='.'
  24.     else
  25.         mask=0
  26.         for adapter in 0 1; do
  27.             if lsof -p $vdrpid 2>/dev/null | grep -q "adapter$adapter/frontend"; then
  28.                 mask=$(($mask + $adapter + 1))
  29.             fi
  30.         done
  31.         if [ $mask -eq 0 ]; then
  32.             status='-'
  33.         else
  34.             status=$mask
  35.         fi
  36.     fi
  37.     stamp=$(date +%s)
  38.     if [ -n "$PRINT_TIMESTAMPS" -a "$old_status" != "$status" ]; then
  39.         printf '\n[%s]  %s>%s  +%ds\n' $(date +%H:%M:%S) "$old_status" $status $(($stamp - $old_stamp))
  40.         old_stamp=$stamp
  41.     fi
  42.     old_status=$status
  43.     printf "$status"
  44.     sleep 1
  45. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement