scalar variable in system command function

R

Rocky Allen

I have an odd problem with the $file variable listed in the loop below
the syntax of unix split command is as follows:
Usage: split [OPTION] [INPUT [PREFIX]] and split will default to "x" as a
prefix

here is the output of this script (i ^c it)
found file rallen.tar.gz
error splitting file rallen.tar.gz
:2 at ./perl-ATSDailyback line 49.

it remembers the $file variable before and after the system command runs,
but it doesnt add "$file." as a prefix

any thoughts?
thanks in advance


#!/usr/bin/perl

use strict;
use warnings;
use Sys::Hostname;
use POSIX qw/strftime/;

my $error ;
my @errors;
my @filestobackup;
# Variables. This section will need to be modified for each Cooperative.

my $host = hostname;
my $jobstart = localtime();
my $fileformat = strftime('contents-%Y-%m-%d_%H:%M:%S', localtime);
my $contentsfile = "/etc/backup/$fileformat";
my $errorfile = '/tmp/cpioerrors';
my @dirs = ('/working');
my $finderrors = '/tmp/finderrors';
my @largefiles;
#my @tapestat = `mt -f /dev/st0 status`;
#if (scalar(@tapestat) == 0) {
# print "No tape in drive or no tape device on server\n";
# exit 0;
#}



foreach my $backupdir (@dirs) {
chdir($backupdir);
@largefiles = `find . -follow -size +2147483648c -print 2>/tmp/largefilerr`;
foreach my $file (@largefiles) {
$file =~ s/\.\///;
print "found file $file";
system("split -d --bytes=2000000000 $file $file.") == 0 or die "error splitting file $file:$?";
}
@filestobackup = `find $backupdir -follow -print 2> $finderrors`;
}
 
P

Paul Lalli

Rocky said:
I have an odd problem with the $file variable listed in the loop below
the syntax of unix split command is as follows:
Usage: split [OPTION] [INPUT [PREFIX]] and split will default to "x" as a
prefix

here is the output of this script (i ^c it)
found file rallen.tar.gz
error splitting file rallen.tar.gz
:2 at ./perl-ATSDailyback line 49.

Compare this output...

print "found file $file";
system("split -d --bytes=2000000000 $file $file.") == 0 or die "error splitting file $file:$?";

.... with this code.

Do you notice that the output has a newline after each file name?
Do you notice that the code does not?

Somewhere along the way, you neglected to remove the \n from each
filename. You did not find the file "rallen.tar.gz". You found the
file "rallen.tar.gz\n".

perldoc -f chomp

Paul Lalli
 
R

Rocky Allen

Rocky said:
I have an odd problem with the $file variable listed in the loop below
the syntax of unix split command is as follows:
Usage: split [OPTION] [INPUT [PREFIX]] and split will default to "x" as a
prefix

here is the output of this script (i ^c it)
found file rallen.tar.gz
error splitting file rallen.tar.gz
:2 at ./perl-ATSDailyback line 49.

Compare this output...

print "found file $file";
system("split -d --bytes=2000000000 $file $file.") == 0 or die "error splitting file $file:$?";

... with this code.

Do you notice that the output has a newline after each file name?
Do you notice that the code does not?

Somewhere along the way, you neglected to remove the \n from each
filename. You did not find the file "rallen.tar.gz". You found the
file "rallen.tar.gz\n".

perldoc -f chomp

Paul Lalli
}
@filestobackup = `find $backupdir -follow -print 2> $finderrors`;
}
Thank you mr Lalli. You Rock
 
A

Anno Siegel

Rocky Allen said:
I have an odd problem with the $file variable listed in the loop below

Paul Lalli has cleared up your main problem.

Somewhere else you say:
foreach my $file (@largefiles) {
$file =~ s/\.\///;

That is an unsafe way to clean up a file name. Look at what it does
to "a./b". On the other hand, it doesn't deal with "././x" correctly.
File::Spec has the function canonpath() to logically clean up paths.
Use it.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top