Automating pi-hole

Hey lovers of a ad-free web,

I am a very fan of pi-hole. I am trying to write something like a group-policy for some pihole v5 instances. I am doing this because I am that much a fan, that I want to have one pihole in every household of family members (grandparent, aunts and uncles, parents ..) I wite a bash script for a debian based installation. My goal is to manage (adding blocklists, white- and blacklisting etc) some instances from a central point. My script works, but I can´t add blocklists/ and do white/blacklisting via script.

if [ "$ScriptVersion" -eq '1' ]; then
sqlite3 .open /etc/pihole/gravity.db #it´s failing here because "Error near '/' syntax error" I´ve also tried to put the path in a variable $DatabasePath but didn´t helped.
Versions I tried, while being signed in a root:

  1. sqlite3 .open /etc/pihole/gravity.db
  2. sqlite3
    .open /etc/pihole/gravity.db
  3. sqlite3
    sqlite .open /etc/pihole/gravity.db
  4. sqlite3 /etc/pihole/gravity.db <<MY_QUERY
    INSERT INTO adlist (address, enabled, comment) VALUES ("https://domain.com/blocklist.txt", 1, "ANTI Tracking");
    MY_QUERY
    also Tried to put the path in $DatabasePath but still without success.

If I am doing it manually, it just works fine
sqlite3
.open /etc/pihole/gravity.db
INSERT INTO adlist (address, enabled, comment) VALUES ("https://domain.com/blocklist.txt", 1, "ANTI Tracking");

elif [ "$ScriptVersion" -eq '2' ]; then
#add a new blocklist
...
...
else
echo "You´re done BYE!!! "

Can please someone help me how I can manage my Pi-Hole via bash-script?

Try

sudo sqlite3 /etc/pihole/gravity.db "INSERT INTO adlist (address, enabled, comment) VALUES ('https://https://domain.com/blocklist.txt', 1, 'ANTI Tracking');"

Add

There's no nees to re-invent the wheel. Multiple solution for central management of multiple piholes exist. One of them:

Two https:// ?

Oh, I forgot to say I was signed in a root and started the terminal as root.

its just a typo.

I did not just add the sudo. Try the whole line.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.