Tuesday, November 16, 2010

Dog cam update: email me when server is down , start wifi and webcam on boot

The Dog Cam project is done for now. On the last post I said I had a few more config files to edit and I would be done.  First thing I wanted to do was to have the Dog cam server connect to wifi when it was turned on without having to log on. To do so I made sure wpa_supplicant was installed and then I had to edit:


Adding the part in red below

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet static

    wpa-ssid (wifirouter)
    wpa-psk (wifipassword)

Then I added webcam to


#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

webcam /root/.webcamrc

exit 0

I had to make /etc/rc.local executable

to do that I did:

chmod +x /etc/rc.local

/root/.webcamrc trailing webcam is the config file I want it use

webcam /root/.webcamrc

The final thing was to write a script that would email and text me if the server went down.Using ping, grep and sendEmail

ping -c 5 > ping.log ;
GREP_STRING=`grep -c Unreachable /home/USERNAME/.logs/ping.log`
if [ $GREP_STRING -ne 0 ]
(sendEmail -t -t -f -u "Dog Cam" -m "Down" -s -xu EMAIL-USERNAME -xp EMAIL-PASSWORD)

So I set up crontab:

*/5 * * * * /usr/bash /home/USERNAME/.bashscripts/

Done for now.