Skip to content

Instantly share code, notes, and snippets.

@Nurmukhamed
Last active May 14, 2026 04:50
Show Gist options
  • Select an option

  • Save Nurmukhamed/88c73ca7f2f612238610c2ef8d5309bc to your computer and use it in GitHub Desktop.

Select an option

Save Nurmukhamed/88c73ca7f2f612238610c2ef8d5309bc to your computer and use it in GitHub Desktop.
[Unit]
Description=Beeline Scanner - 5-minute Task
[Service]
EnvironmentFile=-/opt/beelinescanner/environments.sh
WorkingDirectory=/opt/beelinescanner
Type=oneshot
ExecStart=/opt/beelinescanner/script.sh
# Option A: Run at fixed 5-minute clock intervals (e.g., 10:00, 10:05, 10:10)
OnCalendar=*:0/5
# Option B: Alternatively, run every 5 minutes relative to when it last started
# OnUnitActiveSec=5min
# Ensures the task runs immediately if the system was off during a scheduled time
Persistent=true
[Install]
WantedBy=timers.target
MACADDRESS="XX:XX:XX:XX:XX:XX"
RTSPUSER="admin"
RTSPPASS="12345678"
GO2RTCCAMERANAME="camera6_channel1"
#!/bin/bash
# Check if programs are installed.
export DEBIAN_FRONTEND=noninteractive
apt-get update
INSTALL_PROGRAM=""
if command -v curl >/dev/null; then
echo "CURL is installed."
else
INSTALL_PROGRAM="${INSTALL_PROGRAM} curl"
fi
if command -v jq >/dev/null; then
echo "JQ is installed."
else
INSTALL_PROGRAM="${INSTALL_PROGRAM} jq"
fi
if command -v nmap >/dev/null; then
echo "NMAP is installed."
else
INSTALL_PROGRAM="${INSTALL_PROGRAM} nmap"
fi
echo ${INSTALL_PROGRAM}
if [ -n "$INSTALL_PROGRAM" ]; then
apt-get -qq -y install ${INSTALL_PROGRAM} --no-install-recommends
fi
if command -v yq >/dev/null; then
echo "YQ is installed."
else
curl -Ls "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64" \
-o /usr/local/bin/yq
curl -Ls "https://github.com/mikefarah/yq/releases/latest/download/checksums" \
-o /tmp/checksums
if grep -q "$(sha256sum /usr/local/bin/yq | awk '{ print $1}')" /tmp/checksums; then
echo "YQ checksum is matched."
else
echo "YQ checksums is not matched"
exit 1
fi
chmod 0755 /usr/local/bin/yq
fi
mkdir -p /opt/beelinescanner
echo "Downloading script, environment, systemd timer, systemd service files."
curl -Ls "https://gist.githubusercontent.com/Nurmukhamed/88c73ca7f2f612238610c2ef8d5309bc/raw/67692232fcc9c1961df6b9695687070d3fb58731/script.sh" \
-o /opt/beelinescanner/script.sh
chmod 0755 /opt/beelinescanner/script.sh
curl -Ls "https://gist.githubusercontent.com/Nurmukhamed/88c73ca7f2f612238610c2ef8d5309bc/raw/67692232fcc9c1961df6b9695687070d3fb58731/environments.sh" \
-o /opt/beelinescanner/environments.sh
chmod 0755 /opt/beelinescanner/environments.sh
curl -Ls "https://gist.githubusercontent.com/Nurmukhamed/88c73ca7f2f612238610c2ef8d5309bc/raw/67692232fcc9c1961df6b9695687070d3fb58731/beelinescanner.timer" \
-o /etc/systemd/system/beelinescanner.timer
curl -Ls "https://gist.githubusercontent.com/Nurmukhamed/88c73ca7f2f612238610c2ef8d5309bc/raw/67692232fcc9c1961df6b9695687070d3fb58731/beelinescanner.service" \
-o /etc/systemd/system/beelinescanner.service
systemctl daemon-reload
systemctl enable --now beelinescanner.timer
#!/bin/bash
# Constants
BEELINELAN="192.168.8.0/24"
FOLDER=/opt/beelinescanner
OUTPUTFILE=output.txt
FRIGATECONFIGFILE="/opt/frigate/config/config.yaml"
DOCKERCOMPOSEFILE="/opt/docker/main"
RTSPPORT="554"
RTSPPATH="cam/realmonitor?channel=1&subtype=0"
RTSPSTRING="rtsp://%s:%s@%s:%s/%s"
PWD="$(pwd)"
echo ${PWD}
# Use nmap to scan 192.168.8.0/24 network and save results in xml file.
nmap -sn "${BEELINELAN}" -oN "${FOLDER}/${OUTPUTFILE}" > /dev/null
# Set variables
ISFOUND="0"
IPADDRESS=""
HOSTNAME=""
# Reading file line by line.
while IFS= read -r line; do
if [[ "${line}" =~ "Nmap scan report for" ]]; then
LOOPIPADDRESS=""
LOOPMACADDRESS=""
if [[ "${line}" =~ [\(\)] ]]; then
LOOPIPADDRESS="$(echo ${line} | awk '{ print $6 }')"
LOOPIPADDRESS="$(echo ${LOOPIPADDRESS:1})"
LOOPIPADDRESS="$(echo ${LOOPIPADDRESS%?})"
else
LOOPIPADDRESS="$(echo ${line} | awk '{ print $5 }')"
fi
fi
if [[ "${line}" =~ "MAC Address:" ]]; then
LOOPMACADDRESS="$(echo ${line} | awk '{ print $3 }')"
fi
if [[ "${LOOPMACADDRESS}" == "${MACADDRESS}" ]]; then
IPADDRESS="${LOOPIPADDRESS}"
ISFOUND="1"
fi
done < "${FOLDER}/${OUTPUTFILE}"
# Get current ip address of camera from frigate config file using yq.
# Then strip rtsp line to ip address.
OLDIPADDRESS="$(yq ".go2rtc.streams.${GO2RTCCAMERANAME}[0]" "${FRIGATECONFIGFILE}")"
OLDIPADDRESS="$(echo $OLDIPADDRESS | sed 's%rtsp://%%')"
OLDIPADDRESS="$(echo $OLDIPADDRESS | sed "s%:${RTSPPORT}%%")"
OLDIPADDRESS="$(echo $OLDIPADDRESS | sed "s%/${RTSPPATH}%%")"
OLDIPADDRESS="$(echo $OLDIPADDRESS | sed "s%${RTSPUSER}:%%")"
OLDIPADDRESS="$(echo $OLDIPADDRESS | sed "s%${RTSPPASS}@%%")"
if [[ "${ISFOUND}" == "1" ]]; then
if [[ "${IPADDRESS}" != "${OLDIPADDRESS}" ]]; then
CURRENTRTSPSTRING="$(printf "${RTSPSTRING}" "${RTSPUSER}" "${RTSPPASS}" "${IPADDRESS}" "${RTSPPORT}" "${RTSPPATH}")"
yq -i ".go2rtc.streams.${GO2RTCCAMERANAME}[0] = \"${CURRENTRTSPSTRING}\"" "${FRIGATECONFIGFILE}"
cd "${DOCKERCOMPOSEFILE}"
docker compose down -v frigate
docker compose up -d frigate
cd "${PWD}"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment