Perl and tar not cooperating in a shell script 
Author Message
 Perl and tar not cooperating in a shell script

I've been having problems with my (homemade) backup system.
Occasionally, tar is asked to back up file with spaces or other odd
characters in their names.  These files are _always_ lost in the
backup.  What I would like to do, is to encapsulate each filename within
quotes.  I.e., tar file1 file2 file number 3
 Would become: tar "file1" "file2" "file number 3" etc..

My backup currently does the following (basically):
        1. use "find" to grab all the files needed to be backed up and dump the
results into a temporary file.
        2. use "tar cf $backup_device `cat $temporary_file`" to backup the
files.

I would like to modify step 2:
        2. use "tar cf $backup_device `cat $temporary_file |
quo{*filter*}capsulate.pl`" to backup the files.

I have been using the following as 'quo{*filter*}capsulate.pl':
#!/usr/bin/perl -w


        $line =~ s/\n//;
        print STDOUT "'$line' ";

Quote:
}

**THE PROBLEM**
tar _ALWAYS_ reports that it cannot find the files output by
quo{*filter*}capsulate.pl.  I think that it is possible that the (') character
returned by the perl script may be of a different code value than that
expected by tar.  I have also tried (\") in place of (') in the above
code snippet.  Neither seem to work.

**MY QUESTION**
Should I be using a hex code in the above code snippet in place of (')
or (")?  Can anybody else get this system to work?

Matt



Fri, 03 Dec 1999 03:00:00 GMT  
 Perl and tar not cooperating in a shell script

Quote:

> I've been having problems with my (homemade) backup system.
> Occasionally, tar is asked to back up file with spaces or other odd
> characters in their names.  These files are _always_ lost in the
> backup.  What I would like to do, is to encapsulate each filename within
> quotes.  I.e., tar file1 file2 file number 3
>  Would become: tar "file1" "file2" "file number 3" etc..

> My backup currently does the following (basically):
>    1. use "find" to grab all the files needed to be backed up and dump the
> results into a temporary file.
>    2. use "tar cf $backup_device `cat $temporary_file`" to backup the
> files.

> I would like to modify step 2:
>    2. use "tar cf $backup_device `cat $temporary_file |
> quo{*filter*}capsulate.pl`" to backup the files.

> I have been using the following as 'quo{*filter*}capsulate.pl':
> #!/usr/bin/perl -w



>         $line =~ s/\n//;
>         print STDOUT "'$line' ";
> }

> **THE PROBLEM**
> tar _ALWAYS_ reports that it cannot find the files output by
> quo{*filter*}capsulate.pl.  I think that it is possible that the (') character
> returned by the perl script may be of a different code value than that
> expected by tar.  I have also tried (\") in place of (') in the above
> code snippet.  Neither seem to work.

I think this is a shell/tar problem, not a perl problem.  I suggest
ditching your perl script and just doing:

        tar cf $backup_device --files-from $temporary_file

which is faster, easier, and won't violate any command line argument limits
your shell might impose.  Also it works.

-Tom



Fri, 03 Dec 1999 03:00:00 GMT  
 Perl and tar not cooperating in a shell script

Quote:


> > I've been having problems with my (homemade) backup system.
> > Occasionally, tar is asked to back up file with spaces or other odd
> > characters in their names.  These files are _always_ lost in the
> > backup.  What I would like to do, is to encapsulate each filename within
> > quotes.  I.e., tar file1 file2 file number 3
> >  Would become: tar "file1" "file2" "file number 3" etc..

 -- snip snip --
> > **THE PROBLEM**
> > tar _ALWAYS_ reports that it cannot find the files output by
> > quo{*filter*}capsulate.pl.  I think that it is possible that the (') character
> > returned by the perl script may be of a different code value than that
> > expected by tar.  I have also tried (\") in place of (') in the above
> > code snippet.  Neither seem to work.

> I think this is a shell/tar problem, not a perl problem.  I suggest
> ditching your perl script and just doing:

>         tar cf $backup_device --files-from $temporary_file

> which is faster, easier, and won't violate any command line argument limits
> your shell might impose.  Also it works.

> -Tom

Your solution works!  Thank you!

        Matt



Sat, 04 Dec 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. shell script from within a shell script

2. Tar'ing files and changing directory in the tar file using Archive::Tar

3. Calling shell scripts or shell commands from Perl

4. Script Ok from the Shell, not Ok from Apache Rh8.0

5. Setuid shell scripts not allowed

6. Scripts work from shell but not browser

7. Help, shell commands not working from within script

8. tar in Perl, system or not

9. Emacs Perl addons: cooperate with h2xs

10. Scheme Shell: Shell Scripting for the 90's

11. Bourne Shell Script to Perl script converter?

12. Passing variables from Perl script to shell script

 

 
Powered by phpBB® Forum Software