Page 1 of 1

Auto Pause when you go out

PostPosted: 03 Jul 2016, 12:36
by m0oml
Yet another bodged script

make sure you phone always gets the same ip address from your router

Code: Select all
#!/bin/bash
# This Script is to ping a ip addres ( My mobile phone)
# and pause music when it fails to detect a host
# it is crude dirty and badly written any sugestions
# or criticism welcome
#
# Trevor Cockayne trevoml@gmail.com

count=2
weplay=0
wepause=0

for (( ; ; ))
        do
      count=$(ping -4 -c2 192.168.1.136 | grep 'received' | awk -F',' '{ print $2}' | awk '{ print $1}')
            if [ $count -eq 0 ]; then
            if [ $wepause -eq 0 ]; then
                  mpc pause > /dev/null 2>&1
                  let wepause=1
               else
                  let weplay=0
               fi
         else
            if [ $weplay -eq 0 ]; then
                  mpc play > /dev/null 2>&1
                  let weplay=1
               else
                  let wepause=0
               fi
        fi
sleep 10
done

Re: Auto Pause when you go out

PostPosted: 22 Jan 2018, 10:06
by watchdog
Hello,

I'm glad you made this script! Thank you!

I could use some info in order to make it work, tho. Ok with ssh access, but I'm almost a noob in coding.

Could it be possible to "auto-start" and "auto-pause" playing when it detects at least one (of my two) phones ?
It's ok with "auto-pause" but I don't know if its possible for autostart playing a queue.

Thanks in advance.