I spy with my XO laptop

Posted:


With a small bit of scripting, I have created a cron task on my XO laptop to take pictures every minute and upload them to taskboy.com. You can see the result on my spycam page.

The camera is positioned in a second story window looking out on my amazing backyard. Will you see a deer? A cat? Chupacabra? You’ll have to keep coming back to find out!

The script on my XO looks like this:

#!/usr/bin/perl -- -*-cperl-*-
use strict;
use POSIX qw[strftime];

my $outfile="foo.png";
my $web_dir="/path/to/spy";
my $ssh_id = q[user@myhost.com];

my $remote_name=strftime("%Y-%m-%d_%H-%M-%S.png", 
                  localtime());
my $delete_horizon=7; 

# Take the picture
my $cmd = qq[gst-launch-0.10 v4l2src ! ffmpegcolorspace ] 
  . qq[! pngenc ! filesink location=$outfile ]
  . qq[> /dev/null 2> /dev/null];

system($cmd);

# Is this picture mostly empty?
if (-s $outfile < 80_000) {
    exit 1;
}

# Upload to taskboy
$cmd = qq[scp -q $outfile $ssh_id:$web_dir/$remote_name];
system($cmd);

# Remove old link ; relink to new file
$cmd = qq[ssh $ssh_id 'cd $web_dir && rm current.png;]
  . qq[cd $web_dir && ln -s $remote_name current.png'];
system($cmd);

# Remove older pictures
$cmd = qq[ssh $ssh_id "find $web_dir -name '*.png' ] 
  . qq[-ctime +$delete_horizon -exec 'rm' '{}' ';'"];
system($cmd);

# Remove local file
unlink($outfile);

In other news, did you know the XO appears to have sshd running by default? Very useful for those of us that just want a command line anyway.

I am at the very pinnacle of 1997 technology.