Cannot get shell to copy directories from within a Perl scrip t

Cannot get shell to copy directories from within a Perl scrip t

Post by Timothy Johns » Thu, 21 Nov 2002 06:06:28



Try passing $safe as a parameter to backThatThangUp().  Also, the ampersand
before the function name is really not used anymore, and is supposed to
denote that you wish to turn off prototyping.  Anyway, try passing $safe as
a parameter, and add the following line at the beginning of the function:

my $safe = $_[0];


function (I would recommend passing a reference).

-----Original Message-----

Sent: Tuesday, November 19, 2002 12:30 PM

Subject: Cannot get shell to copy directories from within a Perl script

Hello all --

The script I'm working on is here:

#!/usr/bin/perl
# A script to back up all of the important information on <servername>.
# Written by: C*te M. Oliver
# Written on: 11/13/02

use strict;             # Be pedantic.


$safe = '/mnt/hd/backups/';   # Where do we want to back up to?
Consistency!
&getDirs;
&backThatThangUp;

sub getDirs {         # A subroutine that parses the directories in
backUpDirs and reads them into an array.

             or die "Can't Open Back-up Directory File: $!";
   }

sub backThatThangUp { # The subroutine that actually backs up the
directories to $safe.

     $copy = `cp -Rp $_ $safe`;
     print $copy;
     }
 }

I've gotten &getDirs working properly, but I am having some problems
with &backThatThangUp.
There may be a better way to do this within Perl, but I'm not aware of
it. :)

When I run this script, I get this:


cp: missing destination file
Try `cp --help' for more information.
sh: /mnt/hd/backups/: is a directory
cp: missing destination file
Try `cp --help' for more information.
sh: /mnt/hd/backups/: is a directory

(repeated a few more times -- once for each element in the array)

However, I can run the identical command on the command line and the
shell copies the files over to $safe.

I have also tried using File::Copy, but found that it doesn't copy over
directories and doesn't seem to handle arrays very well.  It's quite
possible that I was using it incorrectly, though.  I just began with
Perl a week or two ago -- can someone help point me in the right
direction?

---
C*te Oliver
Junior Systems Engineer
Case Design/Remodeling, Inc.

--



 
 
 

1. Cannot get shell to copy directories from within a Perl script

Hello all --

The script I'm working on is here:

#!/usr/bin/perl
# A script to back up all of the important information on <servername>.
# Written by: Charlotte M. Oliver
# Written on: 11/13/02

use strict;             # Be pedantic.


$safe = '/mnt/hd/backups/';   # Where do we want to back up to?
Consistency!
&getDirs;
&backThatThangUp;

sub getDirs {         # A subroutine that parses the directories in
backUpDirs and reads them into an array.

             or die "Can't Open Back-up Directory File: $!";
   }

sub backThatThangUp { # The subroutine that actually backs up the
directories to $safe.

     $copy = `cp -Rp $_ $safe`;
     print $copy;
     }
 }

I've gotten &getDirs working properly, but I am having some problems
with &backThatThangUp.
There may be a better way to do this within Perl, but I'm not aware of
it. :)

When I run this script, I get this:


cp: missing destination file
Try `cp --help' for more information.
sh: /mnt/hd/backups/: is a directory
cp: missing destination file
Try `cp --help' for more information.
sh: /mnt/hd/backups/: is a directory

(repeated a few more times -- once for each element in the array)

However, I can run the identical command on the command line and the
shell copies the files over to $safe.

I have also tried using File::Copy, but found that it doesn't copy over
directories and doesn't seem to handle arrays very well.  It's quite
possible that I was using it incorrectly, though.  I just began with
Perl a week or two ago -- can someone help point me in the right
direction?

---
Charlotte Oliver
Junior Systems Engineer
Case Design/Remodeling, Inc.

2. Problems with Soundblaster Freedom Project

3. Need help converting/sorting date field from within a Perl scrip t

4. Histoires sans paoles

5. cannot load full program..cannot copy all files

6. Script as argument

7. Run a perl script within perl....

8. FS: 8 19" Color Tektronix X-terminals

9. Lotus 123R24 - selecting directories within a macro question

10. Cannot open PDF within Firewall

11. Exploring UNIX directories within PC SAS

12. Create Network Directory within SAS

13. help with windows directory command from within idl