• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Create a Log file of files copied to a Public Folder, Add to a Perl script a log of files Uploaded

OK, this really is a two part question, here's what currently happens, approx. 8 photographers copy 100s of .eps files to a Public/Shared folder (a Mac running OSX), these files are then uploaded using a perl script run as a cron job, see link below to a previous question for this script.

http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_24578592.html

Part 1
Is there a way to keep track/log of each file copied (date stamped ip address of computer which uploaded file?) to the Public/Shared folder whether this is a perl script or any other way

Part 2
Modify/add to the upload script to also log each file it has uploaded

This is just to give me an audit trail from the upload Mac

Much appreciated in advance
0
mce-man-it
Asked:
mce-man-it
  • 2
1 Solution
 
wilcoxonCommented:
Part 1 - it depends on how the photographers copy the files to the Mac.  If it is ftp, sftp, or some other remote copy, the server should be able to configure logging.  If it is a direct copy onto the Mac from their camera or whatever, there probably isn't (one of the fabulous things HURD would have made easy).

Part 2 - this should work.  It is a modified copy of the final version of the script from the previous question.
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
 
my $username = "xxxxxxx"; #will fill in with user
my $password = "xxxxxxx"; #will fill in with users password
my $SearchDirectory = '/path/to/search';
my $DestDirectory = '/path/to/dest';

open LOG, '>>/path/to/logfile' or die "could not write to the log: $!";
 
my $StartTime = time;
find(\&found, $SearchDirectory);

close LOG;
 
sub found {
    my $mtime = (stat($File::Find::name))[9];
    return unless -f _;            #Skip non normal files (eg: directories/pipes/links...)
    return if -d _;                #Skip directories
    return unless /\.(pdf|eps)$/;  #Skip anything without .pdf or .eps extension
    return unless $StartTime - $mtime > 120;
    my $cmd = qq{/usr/bin/curl -F "overwrite=1" -F "filedata=\@$_" -u $user:$passwd  -s "http://$host/webnative/upload?$DestDir"};
    system("$cmd > /tmp/send_file");
    #Do you want to check to see if it was successful?
    if($?) {
        warn "Error with $File::Find::name\n";
        return;
    }
    print LOG timestamp(), ':  copied ', $File::Find::name, "\n";
    unlink($File::Find::name) or warn "Could not remove '$File::Find::name': $!\n";
}

sub timestamp {
    my ($sec, $min, $hour, $mday, $mon, $yr) = localtime();
    $mon++;
    $yr += 1900;
    return sprintf '%d/%02d/%02d $d:%d:%d', $yr, $mon, $mday, $hour, $min, $sec;
}

Open in new window

0
 
mce-man-itAuthor Commented:
Thanks for the script going to give it a go, shortly.

The photographers just mount the Public folder via afp on there desktops and drag the files to the folder.
0
 
mce-man-itAuthor Commented:
Got the script working thanks for your help just needed a couple of tweeks, i've posted the amends just in case somebody else finds it useful, the line my $host just needed adding back in also just needed to tweek the open log line, i've used the path to where the mac stores its other logs and it is viewable in the Console app, in the line return sprintf there was a $ instead of a %.

As to the first part i'm going to see if turning on logging in the AppleFileService works for logging files copied to the shared folder.

Thanks again for your time
my $host = 'xx.xx.xx.xx';

open(LOG, ">>/Library/Logs/Upload.log") or die "could not write to the log: $!";



return sprintf '%d/%02d/%02d %d:%d:%d', $yr, $mon, $mday, $hour, $min, $sec;

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now