Pages

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:

/etc/network/interfaces 


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
    address 192.168.0.0  
    netmask 255.255.0.0
    gateway 192.168.0.1

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

Then I added webcam to

/etc/rc.local


#!/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


#!/bin/bash
ping -c 5 192.168.0.0 > ping.log ;
GREP_STRING=`grep -c Unreachable /home/USERNAME/.logs/ping.log`
if [ $GREP_STRING -ne 0 ]
then
(sendEmail -t 0000000000@vtext.com -t recipiant@recieve.com -f sender@send.com -u "Dog Cam" -m "Down" -s smtp.send.com -xu EMAIL-USERNAME -xp EMAIL-PASSWORD)
fi


So I set up crontab:

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


Done for now.