Skip to content

Instantly share code, notes, and snippets.

@doriantaylor
Created August 7, 2022 15:07
Show Gist options
  • Save doriantaylor/7f0d872af2ac6d19d388fd9ec656316a to your computer and use it in GitHub Desktop.
Save doriantaylor/7f0d872af2ac6d19d388fd9ec656316a to your computer and use it in GitHub Desktop.
cron script to turn your security camera on and off based on the presence of your phone on the wifi
#!/bin/bash
# This assumes you have https://motion-project.github.io/ installed.
# It also assumes this machine is on the same LAN as your phone.
# Put this script in root's crontab; set it to run every minute.
#
# Copyright 2022 <https://doriantaylor.com/person/dorian-taylor#me>
# License Apache-2.0 <https://www.apache.org/licenses/LICENSE-2.0>
# Change this to your phone's mac address
# (and make sure it isn't spoofing while on your network)
MAC=de:ad:be:ef:ca:fe
phone=$(($(/usr/sbin/arp -a | grep -q $MAC && echo 1) + 0))
motion=$(($(ps ho pid -C motion) + 0))
if [[ $motion -gt 0 ]]; then
if [[ $phone -gt 0 ]]; then
echo "phone is present on the network; killing motion"
kill $motion
fi
elif [[ $phone -le 0 ]]; then
echo "phone has left the network; starting motion"
su motion -c motion
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment