> Hi,
> 
> Thanks all for the help on the mail question a few days back. That's 
> fixed. Now I've run into another problem. I'm trying to copy a file on 
> a local network (off a PC) to my Mac. But when the script is called 
> from within cron, it seems that the script doesn't run. The cron looks 
> like this:
> 
> * * * * * /Users/xxxx/Library/Scripts/backup.pl
> 
> The script is as follows:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my @files = "db1.txt, db2.txt, db3.txt, db4.txt";
> 
> foreach (@files) {
>     rename "/path/to/pc/file/$_", "/Users/xxxx/Documents/$_".".bak";

You should always check that 'rename' succeeded (as apparently it isn't).

rename $oldfile, $newfile or warn "Can't rename file: $!";

$! will then provide you more information as to why its not working.

> }
> 
> exit;
> 
> And finally, should I even use perl to do this? I'm comfortable with 
> the little perl I know, but should I use some sort of bash file -- I've 
> never messed with bash before, but maybe now is a good time to learn. I 
> don't even know if I am referencing "bash" correctly here.
> 

Using Perl is fine, but you want something other than 'rename'.  I
suspect this is failing because you are attempting to move a file across
a filesystem boundary, from perldoc -f rename:

"For example, it will usually not work across file system boundaries,
even though the system mv command sometimes compensates for this."

I would suggest File::Copy instead though make sure to check the docs
and test, I don't have my laptop to check for issues on OS X:

perldoc File::Copy

HTH,

http://danconia.org

Reply via email to