Something
public text v1 · immutable#!/usr/bin/perl
use strict;
use warnings;
use File::Copy "mv";
use File::Path "mkpath";
my $server_path = "/mnt/www/localhost/htdocs/shots";
if(!-d "$server_path/")
{
eval {
mkpath(["$server_path/"]);
}; if($@) {
print "$@\n";
exit;
}
}
my ($day, $month, $year) = (localtime())[3 .. 5];
$year += 1900;
$month++;
my $filename = sprintf("shot-%04d-%02d-%02d", $year, $month, $day);
print "Shooting.\n";
my $tmpfile = $filename;
`scrot /tmp/$tmpfile.png -t 25`;
my $last = (glob("$server_path/$filename-???.png"))[-1];
my $num;
if($last)
{
$num = substr($last, rindex($last, "-") + 1);
$num = substr($num, 0, index($num, "."));
$num++;
}
else
{
$num = "000";
}
$filename = "$filename-$num";
print "Shot saved as $server_path/$filename.png\n";
mv("/tmp/$tmpfile.png", "$server_path/$filename.png");
print "Thumb saved as $server_path/$filename-thumb.png";
mv("/tmp/$tmpfile-thumb.png", "$server_path/$filename-thumb.png");