Jan 202013
 

I have been playing around with Motion on one of my Linux boxes, and got annoyed at the constant stream of emails that I am receiving as I have setup Motion to send an email to myself when it detects motion, so I wrote up a short script to activate or deactivate motion if it can pick up certain devices by pinging them.

It’s not foolproof as my wifi is playing up a bit and some devices do not respond by ping sometimes, but it’s useful for deactivating something when you approach and reactivating it when you leave, or vice versa depending on your use of this script.
Setting this script up as a cronjob will allow it to run every say 5 minutes for automation.


#!/bin/bash
PeopleAround=0
people=( 192.168.2.72 192.168.2.117 )
MotionStarted=`wget -o getlog -O /usr/scripts/status http://localhost:8080/0/detection/status | cat /usr/scripts/status | sed -e 's/<[^>]*>//g' | tail -n 3 | head -n -2`

for ip in "${people[@]}"; do
PersonAround=`ping -c 1 $ip | grep '64 bytes' | wc -l`
if [[ PersonAround -eq 1 ]]; then
PeopleAround=1
break
fi
done

if [[ $PeopleAround -eq 1 ]]; then
if [[ "$MotionStarted" =~ "ACTIVE" ]]; then
wget -O /usr/scripts/status http://127.0.0.1:8080/0/detection/pause
echo "People around, stopping motion" $run | mail -s 'Motion stopped' YOUR@EMAIL.COM
fi
else
if [[ "$MotionStarted" =~ "PAUSE" ]]; then
wget -O /usr/scripts/status http://127.0.0.1:8080/0/detection/start
echo "No One around, Starting motion" $run | mail -s 'Motion started' YOUR@EMAIL.com
fi
fi

Share
Aug 302012
 

So I’ve gotten this crazy idea into my head that I can write a script that will detect whether you have a USB WiFi dongle plugged in, whether you have the right drivers installed, and if you do, then it will ask you for WiFi details and attempt to connect. Or if you don’t have the right drivers / firmware etc, it will detect what hardware you have and install the right devices.

Now, in order to do that, I need to do some data gathering. The information that I need ?
Is this –
If you have a USB wifi adapter plugged into your Raspberry Pi, run these commands, and post the output into the comments.

Run lsusb first, to determine the Bus and Device that the USB Wifi adapter is on, and then run lsusb with the -v and -s arguments to display just the information relevant to the WiFi Adapter.

lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 006: ID 0c45:627b Microdia PC Camera (SN9C201 + OV7660)
Bus 004 Device 002: ID 0846:6a00 NetGear, Inc. WG111v2 54 Mbps Wireless [RealTek RTL8187L]
lsusb -v -s 004:002

If I can get enough information, then I may be able to write the script !

Thanks !

Share
Jul 012012
 

I’ve created a script to make mounting image files created by dd easier. It will mount an img file onto a directory via the loopback mechanism supported by linux, so your kernel must have loopback support for this script to work.
It also makes use of the mount, fdisk, and file commands so they must be installed also.
This is just the first version, it will tell you if something is mounted when you run the script on the file, and if it is mounted attempt to unmount it.
The script will also need to be run as root or with sudo as mounting from the command line needs to be done with superuser permissions.

The script can be downloaded here

Run it with the command ./imgmgt.sh

Any feedback, feel free to leave a comment 🙂

Update 1/7/2012 – Just updated this to fix up something I did wrong, so anyone who’s already grabbed this, please get it again from the link above. Thanks !

Share