phonehome.sh

#!/bin/bash

## Written by Jacob Braun, http://five.jacobbraun.com

## These should be pretty self explanatory
username=yourusername
password=yourpassword
server=yourftpserver
returnfile=phonehome
website="http://yourwebsite/"$returnfile
## No leading or trailing slashes on remotepath
remotepath=no/leading/or/trailing/slashes

## A simple test for internet access. If no internet access found, or the file is unavailable, pause for 20 seconds then check again.
site=`(curl -s $website)`
if [ "$site" != "true" ]; then
        sleep 20;
fi;

## Check internet access again. If detected, run the capture script.
site=`(curl -s $website)`
if [ "$site" == "true" ]; then
        ##Don't modify anything below here
        externalip=`(curl -s http://checkip.dyndns.org | awk '{print $6}' | awk ' BEGIN { FS = "<" } { print $1 } ')`
        date=`(date +%s)`
        ## Set filename of iSight capture and screenshot to the unix timestamp with the external IP address in it with respective extensions
        isight=$date"-ip"$externalip".jpg"
        screenshot=$date"-ip"$externalip".png"
        ## Take an iSight picture
        /usr/local/bin/isightcapture /tmp/$isight
        ## Take a screen grab
        /usr/sbin/screencapture -x -m /tmp/$screenshot
        ## User curl to upload them to the server
        curl -s -T /tmp/$isight -u $username:$password -o --url ftp://$server/$remotepath/
        curl -s -T /tmp/$screenshot -u $username:$password -o --url ftp://$server/$remotepath/
else
        exit 0
fi;
exit 0