Skip to content

Instantly share code, notes, and snippets.

@rcmelendez
Created March 20, 2021 15:01
Show Gist options
  • Save rcmelendez/da03af28aa648c87ad4025f59b06c944 to your computer and use it in GitHub Desktop.
Save rcmelendez/da03af28aa648c87ad4025f59b06c944 to your computer and use it in GitHub Desktop.
Bash shell script that runs Zeek IDS automatically on macOS.
#!/usr/bin/env bash
#
# Bash shell script that starts the Zeek process if it's not running.
#
# Add this script to the root crontab, e.g.:
#*/5 * * * * /Users/roberto/zeek.sh > /tmp/zeek.log 2>&1
#
#
# Version: 1.0.0
# Author: Roberto Meléndez [Cambridge, USA]
# Medium: https://medium.com/@rcmelendez/
# Released: March 19, 2021
set -euo pipefail
# Get the process status and pid
zeek_status=$(/usr/local/bin/zeekctl status | awk 'END {print $4}' || true)
zeek_pid=$(/usr/local/bin/zeekctl status | awk 'END {print $5}' || true)
# Run the deploy command if Zeek is not running
# BPF device permissions have to be changed manually every time our Mac reboots :(
if [[ "${zeek_status}" != "running" ]]; then
chgrp admin /dev/bpf*
chmod g+r /dev/bpf*
/usr/local/bin/zeekctl deploy
else
echo "Nothing to do, Zeek is running with pid ${zeek_pid}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment