This is working quite nicely, here's a sample:
Back door
Drive
HUMAX
Kitchen away since 08:45
Macbook
NAS drive
Nest Labs Inc.
Clare away since 08:34
Paul
pi 2 (study)
pi 3 (sense)
Raspbrewery
router
wifi link
Just a sample of course I'm not publishing info on when we go in and out up here... code is something like this:
#!/bin/bash
DOCROOT=/var/www
FOLDER=${DOCROOT}/devices
arp-scan -l --interface=wlan0 --retry=3 | grep 192.168 > /tmp/arp-scan.txt
while read LINE; do
FILE=$(echo "${LINE}" | cut -f2).txt
NAME=$(echo "${LINE}" | cut -f3)
echo ${NAME} > ${FOLDER}/${FILE}
if [ -f ${FOLDER}/.alias.${FILE} ]; then
cp ${FOLDER}/.alias.${FILE} ${FOLDER}/${FILE}
fi
done < /tmp/arp-scan.txt
DATE=$(date +%s)
for FILE in $(ls -1tr ${FOLDER}); do
MTIME=$(stat -c %Y ${FOLDER}/${FILE})
DIFF=$(expr ${DATE} - ${MTIME})
STATUS=
EXPLANATION=''
if [ ${DIFF} -gt 60 ]; then
if [ ${DIFF} -gt 300 ]; then
EXPLANATION="away since $(ls -l ${FOLDER}/${FILE} | cut -c27-38)"
STATUS=
else
STATUS=
fi
fi
echo ${STATUS} $(cat ${FOLDER}/${FILE}) ${EXPLANATION}
done
I really like unicode in bash scripts, it just looks so wrong 1.
⬅️ Hail Caesar! :: No more swimming until after Christmas ➡️
Paul Clarkeʼs blog - I live in Hythe in the deep South. Wed + dad to two, I'm a full stack web engineer, + I do js / Node, some ruby, python, php etc. I like pubbing, running, eating, home-automation and other diy jiggery-pokery, history, family tree stuff, Television, squirrels, pirates, lego, and TIME TRAVEL.