Skip to content

Instantly share code, notes, and snippets.

@yradunchev
Last active July 30, 2017 20:19
Show Gist options
  • Select an option

  • Save yradunchev/397ae73e3eac84a806bc18ebac0eb3ea to your computer and use it in GitHub Desktop.

Select an option

Save yradunchev/397ae73e3eac84a806bc18ebac0eb3ea to your computer and use it in GitHub Desktop.
block access to sites with cron and unbound
#!/bin/bash
readonly UCONF='/etc/unbound/unbound.conf'
# toggle block on/off, kill chromium, restart unbound
awk -v commentId='#' -v word='include: /etc/unbound/block.conf' '
$0 ~ "(^|[[:punct:][:space:]])" word "($|[[:punct:][:space:]])" {
if (match($0, "^[[:space:]]*" commentId)) {
$0 = substr($0, RSTART + RLENGTH);
system("pkill --oldest chromium")
system("systemctl restart unbound");
}
else {
$0 = commentId $0;
system("systemctl restart unbound");
}
}
{ print }
' ${UCONF} > tmpunboundconf.$$ && mv tmpunboundconf.$$ ${UCONF}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment