i have 2 perl scripts that do the following:
The first is named renamer.pl. the script looks in to a directory namely /home/httpd/htdocs for files named images.jpg(coming from camera). the script renames the images with the date of the image, and moves to a new location namly /home/me/images/. this script is running all the time.
The Second script takes image information (name, date, and size) from the images directory (../me/images/) and insets into MySQL.
What the problem i am having is that the second script only starts manually. is there away i could start it automatically?
I would however prefer something else instead of starting it automatically. I would prefer to combine both scripts, so that when the images are renamed and relocated, in the same time, the data is inserted into MySQL.
I would really appreciate any help. please find enclosed both scripts:
Regards,
Mel
-------------------------------------------renamer.pl #!/usr/bin/perl use strict; use warnings;
=head1 NAME
# renamer - renames files received by ftp, moving them to a new directory
=head1 SYNOPSIS
nohup ./renamer image /home/httpd/htdocs /home/me/images jpg renamer.process &
=head1 DESCRIPTION
#The above instructs renamer to look for files called image.jpg in /home/httpd/htdocs.
#It checks once per minute for such a file to appear. If it sees a
#readable file called /home/httpd/htdocs.jpg it moves it to
#/home/httpd/htdocs/image.200302251530.jpg where the number is a
#time stamp with year (four digits), month, day of the month, hour (in
#24 mode), and minute.
#Read the bugs section closely.
=head1 BUGS
#The original and new directories must be on the same file system. #The program probably does not work on windows systems. #The daemon behavior is weak. #Not much testing has been done, so the script may have other problems.
=cut
my $usage = <<EOUSAGE;
usage: $0 initial_name original_dir new_dir suffix lockfile
example: $0 pic /home/httpd/htdocs /home/me/images jpg /home/me/renamer.process
EOUSAGE
my $check_file = shift or die $usage; my $original_dir = shift or die $usage; my $new_dir = shift or die $usage; my $suffix = shift or die $usage; my $lockfile = shift or die $usage;
##################################
# If you put it into the cron, comment out between the START and END BLOCK, and uncomment
# the section below it so you don't get multiple copies running. Also, comment out the
# lockfile bits above.
#START BLOCK
exit if (fork());
while (-e "$lockfile") {
process($check_file) if (-r "$original_dir/$check_file.$suffix");
sleep 30;
}
#END BLOCK
##################################
#
# process($check_file) if (-r "$original_dir/$check_file.$suffix");
#
##################################
sub process {
my $file = shift;
my @st = (stat("$original_dir/$file.$suffix"));
my ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime($st[10]);
$Year += 1900;
$Month++;
my $stamp = sprintf "%4d_%02d_%02d_%02d_%02d_%02d", $Year, $Month, $Day, $Hour, $Minute, $Second;
print "renaming $original_dir/$file.$suffix to $new_dir/$stamp.$suffix\n";
rename "$original_dir/$file.$suffix", "$new_dir/$stamp.$suffix" or warn "couldn't rename file: $! $file to $new_dir/$file.$stamp.$suffix\n";
############################ # Maybe i could add the MySQL insert here???? ############################
} ______________________________________________________
------------------------------------------infoinsert.pl
#!/usr/bin/perl -w
use strict; use DBI; use Date::Manip;
############################################################################ # # Connect to Database Named cctvimages on the localhost with the root user # $dbh=DBI->connect(DBI:mysql;$database", $user, $password); ############################################################################ #
my $dbh = DBI->connect("DBI:mysql:dbname=cctvimages;host=localhost","root", "********", {'RaiseError' => 1});
my $file; my $size; my $mtime; my $secs;
my $imagedir="/home/me/images"; chdir($imagedir) or die "Can't cd to $imagedir; $!\n"; my @jpegs = <*.jpg>; foreach (@jpegs) { my $file = $_;
#$file = "/home/me/images/2003_03_11_14_32_42.jpg";
($size, $secs) = (stat ($file))[8,9];
my $mtime = &ParseDateString("epoch $secs"); # even after conversion ':' is used to seperate hh and mn and ss
$mtime =~ s/://g; # the above swaps out the ':' for nothing
$file =~ s/\/home\/me\/images\///; # the above strips path
print"size is $size\nmodified is $mtime\nfilename is $file\n";
my $rows_affected = $dbh->do(" INSERT INTO imageinfo VALUES(null, '$file', '$size', '$mtime') ") or die "Do Fails: $DBI::errstr\n";
my $sql = "SELECT * FROM imageinfo"; my $sth = $dbh->prepare($sql);
my $sth = $dbh->prepare($sql); $sth->execute or die"Execute fails: $DBI::errstr\n"; $sth->finish; }
$dbh->disconnect;
_________________________________________________________________ Express yourself with cool emoticons http://messenger.msn.co.uk
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]