Hi,

Well, I guess I'm not out of the woods yet. Below is the script as it is now. But, I keep getting an error/warning, each time the copy is invoked:

Can't copy file: db1.txt - No such file or directory
db1.txt NOT backed up!
Can't copy file: db2.txt - No such file or directory
db2.txt NOT backed up!
Can't copy file: db3.txt - No such file or directory
db3.txt NOT backed up!
Can't copy file: db4.txt - No such file or directory
db4.txt NOT backed up!

I can do a single file, such as "/Users/xxxxxx/Documents/db1.txt", as in the commented line of code below, but using strings, it's not happening. I'm missing something, and as usual, it's probably right in front of my face. Any help would be appreciated.

Thanks,

Mark

----------------------------------------------------------------------
#!/usr/bin/perl -w

use strict;
use File::Copy;

my @dbname = ("db1.txt","db2.txt","db3.txt","db4.txt");
my @dbpath = ("Documents","Documents","Documents","Documents");
my $dirto = "/Users/xxxxxx/Documents/";
my $dirfrom = "/Users/xxxxxx/";
my ($from, $to, $backup, $i);

my $timetest = time;

my ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime($timetest);
$year = substr(1900 + $year,2,2);
$mon++;
if ($mon  < 10) { $mon  = "0$mon";  }
if ($mday < 10) { $mday = "0$mday"; }
my $date = "$mon/$mday/$year";

#copy ("/Users/xxxxxx/Documents/db1.txt", "/Users/xxxxxx/Documents/db1.txt.bak") or warn "Can't copy file: $dbname[$i] - $!\n";

for ($i=0; $i<=$#dbname; $i++) {
$backup = $dbname[$i];
$backup =~ s/^(.+)\.(.+)$/$1-$date\.$2/g;
copy ("$dirfrom$dbpath[$i]/$dbname[$i]", "$dirto$backup") or warn "Can't copy file: $dbname[$i] - $!\n";
if (-e "$dirto$backup") {
print "$dbname[$i] backed up.\n";
} else {
print "$dbname[$i] NOT backed up!\n";
}
}


print "\n\nBackup Complete.\n";
------------------------------------------------------------------------ -----



On Apr 27, 2004, at 10:06 PM, Mark Wheeler wrote:

OK... I got the "foo" in my mailbox, so cron is working. So I'll go with the next step of a basic perl script.

Mark


On Apr 27, 2004, at 8:23 PM, Ken Williams wrote:


On Apr 27, 2004, at 5:07 PM, Mark Wheeler wrote:

Yup. You're right. I missed that one. Here's what I did to simplify the testing of the script.
--------------------------------------------
#!/usr/bin/perl -w


use strict;
use File::Copy;

copy("/Users/xxxxxx/Documents/db1.txt", "/Users/xxxxxx/Documents/db1.txt.bak") or warn "Can't copy file: $!";

print "Backup Completed.";

exit;
---------------------------------------------
I know the cron is firing off the request, because when first tried it, I got Permission Denied in my email box. So I changed the permission to 755 and it still doesn't copy the file. And I get nothing in my email box. I'm a little confused. What am I missing?

First rule when it looks like a script isn't doing anything on OS X: check the line endings. Make sure they're unix-style. If they're Mac-Classic style, running the script won't actually do anything.


First rule when setting up cron jobs: make sure cron itself is running. Set up a job with the same timings as the script in question, but make its action "echo foo" or something like that. You should get an email when it runs. If not, then cron's the problem, not perl. I know you said it worked before, but just to make sure...

 -Ken





Reply via email to