3

I have an odroid-c1+ that I would like to use as a pi-hole server (basically dns blackhole for ad's)

I would like to trigger an led to blink when a string is found in the logfile.

I also have wiringpi installed and working, the example blink.sh works as expected as follows:

PIN=0

gpio mode $PIN out

while true; do
  gpio write $PIN 1
  sleep 0.5
  gpio write $PIN 0
  sleep 0.5
done

How would one go about adding the tailf trigger to this sample?

DanielS
  • 53
  • 6

2 Answers2

2

Untested, but I believe you can feed the output from tail into your while loop:

#!/bin/bash
pin=0
gpio mode $pin out
tail -f logfile | while read entry
do
   if [ "$entry" = "string" ]; then
       gpio write $pin 1
       sleep 0.5
       gpio write $pin 0
       sleep 0.5
    fi
done

Uppercase variable names are traditionally reserved for the shell's use.

miken32
  • 42,008
  • 16
  • 111
  • 154
1

Thank you for the great start miken32!

I've been able to take your sample and tweak it to work for my application with the following:

#!/bin/bash
pin=0
gpio mode $pin out
gpio write $pin 0
tailf /var/log/pihole.log | while read INPUT
do
   if [[ "$INPUT" == *"/etc/pihole/gravity.list"* ]]; then
       gpio write $pin 1
       sleep 1
       gpio write $pin 0
    fi
done

Thanks again for your help!

DanielS
  • 53
  • 6
  • Glad I could help. The way the site works is that you a) vote up any answers that you thought were helpful, and b) mark the one that solved your problem as "accepted" by clicking the green checkmark. Unless you've come up with a totally different solution from the provided ones, you don't need to post an answer to your own question. – miken32 Mar 22 '16 at 17:45