Add GPIO pins for LED on blocked ad alerts

Indeed :slight_smile:

You would think if it looks the same it would be the same, some invisible stuff that Windows creates / removes that Linux requires the opposite of

Well, I can add that to the 0.001% of my current Linux knowledge :smiley:

Hi thanks for this thread - it's been a great help. However I've ran into a small problem at the final hurdle! The LEDs flash 5 times upon reboot but doesn't blink with each new block :frowning:. Everything seems to be in the right place just not reacting to the piHole log file.
I followed the steps in twotonefox's post on 1st Nov '16 and used the updated code on pastebin to get where I am now. Thanks in advance.. Hope everyone is well in lockdown!

hi, i have been racking my brain with this for a few days, i had the 5 flashes but nothing on block.
after looking at the update details of pihole to v5, i had to make changes to the script to get it to work with the database as now it is not a list anymore.

change the last segment of the above to the following

# Watch the pihole.log file for gravity string and quick blink led to indicate a block
tail -f -n1 /var/log/pihole.log | while read INPUT
do
if [[ "$INPUT" == *"gravity"* ]]; then
quickBlink
fi
done

The LED should flash on every entry to the log containing "gravity"

i really hope this helps anyone trying this after v5.0 update.

EDIT-formatting

Probably not related but try tail -F instead of tail -f:

I had not thought of that, I'll give it a try in the morning.
I have got the script working well now but if follow and retry works better I'll give it ago.
I was more trying to get the script to read "gravity" blocks in the log as the previous version was edited by a .list file and not as it is now a .dB which broke the above.

Cheers

I would also put some spaces before & after so you wont blink if "gravity" is in a domain name thats being looked up:

if [[ "$INPUT" == *" gravity "* ]]; then

changes have been made, it seems to run OK to be honest i forgot the log rotated.
good point you made about adding the spaces in the input filter, i am getting less false positives now, i guess i could narrow it down even further by putting:

if [[ "$INPUT" ==*" gravity blocked "* ]]; then

that way the only flashes should only be when the log is updated with "gravity Blocked" in the line.

cheers for the advice.

Hura! It works. I'm now running v5 and have already done the changes suggested in recent posts above. However it wasnt this that fixed it for me, although still very helpful.. I noticed that in the following code there was what appeared to be a rouge 'f' at the end of 'tail' as is shown in the op's code. Example below.

# Watch the pihole.log file for gravity string and quick blink led to indicate a block
tailf /var/log/pihole.log | while read INPUT
do
if [[ β€œ$INPUT” == *"/etc/pihole/gravity.list"* ]]; then
quickBlink
fi
done

Unfortunatly I only noticed this after updating to v5 so I don't know if I could have fixed the issue without the v5 update but never the less, removing that pesky f seems to have done the trick. So, after updating to v5, following the comments above and removing the mystery f, it now looks like this..

#  Watch the pihole.log file for gravity string and quick blink led to indicate$
tail -F -n1 /var/log/pihole.log | while read INPUT
do
if [[ "$INPUT" == *" gravity "* ]]; then
longBlink
fi
done

And seems to work perfectly. :+1:
It may also be worth saying that I started off by removed both the ledPiHoleBlinker.sh file and the crontab -e appendage from the pi and did the entire process as root.
One happy camper.

1 Like

Stretch seems to be the last release still supporting tailf:

pi@noads:~ $ man tailf
[..]
DESCRIPTION
       tailf  is  deprecated.   It  may  have unfixed bugs and will be
       removed from util-linux in March 2017.  Nowadays it's  safe  to
       use  tail -f (from coreutils), in contrast to what the original
       documentation below says.
[..]

Always worked fine for me and was shorter to type :wink:

EDIT: I could always do:

alias tailf='tail -F'