#!/usr/bin/perl -T use warnings; use strict; use Sys::Syslog qw(:DEFAULT setlogsock); use File::Tail; use File::Copy 'mv'; use Proc::Daemon; use POSIX qw/setuid setgid/; my $kernlogfile = '/var/log/big_fat_file'; my $mntpath = '/media/nikon'; my $re = qr/kernel:\s+ Vendor:\s+ NIKON\s+ Model:\s+ NIKON\s+ DSC\s+ E +2100\s+/x; my $srcdir = "$mntpath/dcim/100nikon"; my $pixprefix = 'dscn'; my $destdir = '/home/hue/ftp/pix/priv/nikon'; my $user = 'hue'; $SIG{CHLD} = 'IGNORE'; $SIG{TERM} = \&sigterm_handler; $ENV{PATH} = '/bin:/usr/bin'; sub sigterm_handler { closelog; exit 0; } sub do_log { my $logstring = shift; syslog 'LOG_DEBUG', '%s', $logstring; } sub move_files { system '/bin/mount', $mntpath or do_log "Error mounting $mntpath: + $!", exit 1; chdir $mntpath; # prevent fs from being unmounted under our feet while (glob "$srcdir/$pixprefix*") { $_ =~ m#^($srcdir/$pixprefix[0-9]{4}\.(?:jpg|mov))$#; my $unt = $1; do_log "Unexpected file name $_", next unless defined $unt; do_log "Moving $unt"; mv $unt, $destdir or do_log "Error moving $_: $!"; #, + next; } chdir '/'; system '/bin/umount', $mntpath or do_log "Error unmounting $mntpat +h: $!"; do_log "Finished moving"; exit 0; } Proc::Daemon::Init; my (undef, undef, $uid, $gid) = getpwnam $user or do_log "User $user u +nknown", exit 1; setlogsock 'unix'; openlog 'nikon.pl', 'pid', 'LOG_LOCAL0'; my $tailfile = File::Tail->new ( name => $kernlogfile, maxinterval => 5, adjustafter => 10 ); while (defined (my $line = $tailfile->read)) { next if $line !~ $re; do_log "Camera detected"; defined (my $pid = fork) or do_log "Error forking: $!", next; unless ($pid) { setgid $gid; do_log "Error setting gid $gid", exit 1 if $!; ## /bin/mount needs both uid and euid to be set setuid $uid; do_log "Error setting uid $uid", exit 1 if $!; move_files; } } do_log "Something wicked happened reading $kernlogfile. Exiting..."; $SIG{TERM}->();

In reply to Saving digital camera photographs by Hue-Bond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.