How do I add list via cli

I want to create a cron job which would update list from wally3k periodically. but looking at the documentation i couldn't find a command to add list from cli. Has something like this already exist, or am i just overlooking here.

Adlists are for individual URL's only. If you want to add a selection of adlists from the command prompt, you will need a repeating loop to get them all.

This SQL command will enter a single adlist into the gravity database. You would substitute your URL and comments as needed:

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

That said, I'm not a big fan of cron scripts to do this sort of stuff. It's unattended, and if there are problems your Pi-hole can be out of action until you fix it.

My preference would be a calendar reminder for whatevery peridocity you want to do this. At that time, run the following command to remove your existing adlists:

sudo sqlite3 /etc/pihole/gravity.db "DELETE FROM adlist"

Then, go the website, select the lists you want, copy to the clipboard (for example, the list of URL's on the ticked list). Then go to the web admin GUI, paste the lot into Group Management > adlists.

Then rebuild gravity.

The entire process takes less than a minute, plus the time required for gravity to rebuild.

1 Like

Thank you for the guidance and help, Calendar reminder does sound like a good option as well

I am doing something more if I need to add more than one ad list from a file
something like @WaLLy3K blacklist.

cat <blacklistfile> | xargs -n1 -I{} sudo sqlite3 /etc/pihole/gravity.db "INSERT INTO adlist (address, enabled, comment) VALUES ('{}', 1, 'comment');"