Help - Search - Member List - Calendar
Full Version: Perl backup script. I need to pointed in the right direction
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
grocery_stocker
Given the following lines of code:

#!/usr/bin/perl

#Just move all the backup files created by emacs to a dummy directory

my $current_dir = "pwd";
my $command = "cp";
my $backup_dir = "/backup/";
my $dest_dir = "current_dir" . "backup_dir";
my $search_dir = 'ls *.pl~';

open(MOVE, " $command");

I don't know how to have perl move the files with the ~ to the backup
directory.

I did try something like:

@ARGV = `ls *.c~`;

$total = scalar(@ARGV);

for($i=0;$i<$total;$i++) {
`cp $ARGV[$i] $dest_dir `
}

But it didn't work. Any ideas?

cgavos
You need something like that

#!/usr/bin/perl

use warnings;
use strict;


my $current_dir=`pwd`;
## Note these are note single
## quotes this is a backquote
## in a uk keyboard is located above the tab key
chop($current_dir);
my $command=`which cp`; #backquote
chop($command); # remove n character
my $backup_dir="/path/to/destination/";
## absolute path to
## destination with trailing /
my @search_dir=`ls *.pl~`;#backquote
my $full_cmd;

for (my $i=0; $i<$#search_dir; $i++) {
chop($search_dir[$i]);
$full_cmd="$command $current_dir/$search_dir[$i] $backup_dir";
print "$full_cmdn";
## Once you are happy with the command to be executed
# uncomment the following line
# system($full_cmd);
}


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.