1

I want to pause/sleep the elif part but keep the other elif parts working . I don't want the whole script to sleep if 1 sensor goes off.

#!/bin/sh

while true;  do
    valid=""


    scan=`./script`

    if [ "$scan" = "$valid" ]; then
        echo "Good value"

    else
        echo "Bad value"

    fi

    sleep 5
done

exit

So if 1 sensor is triggered it waits for a couple seconds before sending a pushbullet alert for that 1 sensor , but it doesn't cause other sensors to stop sending alerts if the 1 sensor is delayed.

I don't want to be informed every time a sensor goes off I want their to be a delay so it doesn't keep sending me alerts.

  • Why isn't it required? – securitytestman Dec 28 '18 at 11:31
  • 1
    @securitytestman Regarding the '..doesn't sleep the other elif statement..' part from your question. The elif blocks are read sequentially, so there is no parallel operation happening there. – Haxiel Dec 28 '18 at 11:37
  • Haxiel does this mean if I want them to act as different parts of the script I will need to use something other than elif? – securitytestman Dec 28 '18 at 11:59
  • @securitytestman Please use the '@username' notation when you reply, so that I can get a notification for your comment. As for your question, the answer is yes. If you want to run different blocks of code in parallel, you'll need more advanced tools. – Haxiel Dec 28 '18 at 12:38
  • Is it intentional that echo "Good Read"; echo "Your code is " $scan is only executed for the door bell? – nohillside Dec 28 '18 at 14:09
0
#!/bin/bash
#again you must use bash... 
valid[0]=160650648 ; valid[1]=163686025
valid[2]=120806542 ; valid[3]=37206841
i=0

while sleep 5;  do
    scan=$(./RFSniffer)
    if [ "$scan" == "$oldscan" ]; then
    i=$((i+1))
    #if i is minor than 10 restart loop...
    #So a alert will not be displayed again after 50 seconds...
        if [ "$i" -lt "10" ]; then
            continue
        else 
            i=0
        fi
    fi

    case $scan in 
           ${valid[0]})
               echo "Good Read"
               echo "Your code is " $scan
               ./buzzer.sh &
               omxplayer -o local sleighbells.mp3
               curl -u "code": https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="DoorBell" &
            ;; 
            ${valid[1]})
                curl -u "code": https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="front sensor" &
            ;;
            ${valid[2]})
                curl -u "code": https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="Back door sensor" &
            ;;
            ${valid[3]})
                curl -u "code": https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="Second sensor" &
            ;;
            *)
               echo "BAD READ:  your code and the valid don't match"
               echo "Your correct valid code should be " $scan
            ;;
    esac

    oldscan=$scan
    scan=''
    #sleep 5 not needed sleep 5 is in while condition 

done

EDIT: see comments..

  • Ops missing a quote... Try again. – Luciano Andress Martini Dec 28 '18 at 12:03
  • A important question? Do you want to make all the conditions to be hit? Even if one of them are true? – Luciano Andress Martini Dec 28 '18 at 12:05
  • Well I want their to be a delay if true 2 is a sensor and I keep moving it goes off every 5 seconds which is very annoying. I want their to be a delay before sending me an alert. – securitytestman Dec 28 '18 at 12:06
  • You want to check all the conditions again after 5 seconds? All the conditions must be checked even if one of them are true? what is your native language? I am a brazilian speaker (brazil native language is portuguese) maybe I can try to understand you in your other language if it is derivated from latin. – Luciano Andress Martini Dec 28 '18 at 12:08
  • So basically the script is looking out for a signal for a motion sensor. If I was to move near the sensor it will keep sending alerts every 5 seconds I only want alerts to send out every minute or so but still let me know if any other sensors are triggered within that minute (they also need a delay). Does that sense? – securitytestman Dec 28 '18 at 12:13
0

Am I correct when paraphrasing "The script should independently deliver the scans read but block each scan after occurrence for one minute"?

Your script has some opportunities to simplify / optimize, and I'm assuming you're using bash (hoppla - bash tag edited away...?) despite the shebang indicating other... So while implementing the one minute pause for the individual scans, I tried also to reap the opportunities (using echo for the commands not installed on my system - remove if happy with the operation). Try this and feel free to adapt:

VALID=(160650648 163686025 120806542 37206841)                          # define valid scans
BODY=(DoorBell "front sensor" "Back door sensor" "Second sensor")       # define body tests

while true
  do    scan=$(./RFSniffer)

        for IX in "${!VALID[@]}" "${#VALID[@]}"                         # 0 - 3 elements, and 4 to identify bad reads
          do    if [ "${scan:-FALSE}" = "${VALID[IX]}" ]                # compare 4 elements, the 5. tries to compare to "" empty
                  then  echo "Good Read"
                        echo "Your code is " $scan

                        if (( $SECONDS > ${LAST[IX]} + 60 ))            # test for one minute pause
                          then  if [ "$IX" = 0 ]                        # do this just for the "door bell"
                                  then  echo ./buzzer.sh
                                        echo omxplayer -o local sleighbells.mp3
                                fi

                                echo curl -u "code": https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="${BODY[IX]}" # &

                                LAST[IX]=$SECONDS                       # keep last scan occurrence
                          else  echo "pausing "                         
                        fi

                        break                                           # if good read - break out of the for loop to avoid the bad read msg
                fi

                if [ "$IX" = "${#VALID[@]}" ]                           # the fifth loop means no valid scan found

                  then  echo "BAD READ:  your code $scan and the valid ones don't match"
                        echo "Your correct valid code should be one of ${VALID[@]}"
                fi
          done

        sleep 5
  done
  • Well if sensor 1 was set off I would like it to only be able to send 1 alert within a period of a minute or so, but not stop the those other sensors from sending alerts whilst sensor 1 is paused from sending alerts. – securitytestman Dec 28 '18 at 15:49
  • This is exactly what I was targeting at with above. Did you agree to my paraphrase? Did you try the code? – RudiC Dec 28 '18 at 15:52
  • This doesn't work unfortunately doesn't pause, it also doesn't send the alert through pushbullet either. – securitytestman Dec 30 '18 at 18:32
  • "Doesn't work" doesn't really help identifying errors. It worked for me when I did a read scan in lieu of the RFsniffer; it echoed the relevant commands once, and then paused for a minute, per valid scan. Did you remove the echo from the pushbullet command? – RudiC Dec 31 '18 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.