I'm trying to replace a working bash script that uses tar and ssh, with a perl script using system() and the OS(Linux) provided tar and ssh, and am having trouble getting all of the options to work.

I'm trying to piece it together one step at a time and so far this is all I can get working:

my @args = ("/bin/tar", "czvf", $storageLocation.$archiveName, $arc +hiveDir ); system(@args) == 0 or die "system @args failed: $?";
If I try adding things like --exclude-from=$localdir I get various errors depending on where I put the--exclude-from.

Here's the line from the working bash script I'm trying to copy.

tar -czvf - -g $BACKEDUP --index-file $INDEXFILE --exclude-from $MYEX +CLUDES --totals /home/user1/ | ssh remote_machine "cat > /mnt/mount_p +oint/dir1/$FILENAME"
At this point I haven't tried to get the other options working as I thought this would be the simplest. I suspect piping the output to ssh will be a challenge as well and am saving that for last.

In the process of trying to get this working with system() I wondered if I should really be using Archive::Tar and Net::SSH::Perl? My primary reason for using the OS provided tar and ssh is that I thought it would be simpler and provides behavior that I'm familiar with. Then once I had this working I could switch to the more complex(?) task of using Archive::Tar and Net::SSH:Perl.

Any advice or pointers?

And to keep this all in perspective, I'm doing this project for learning purposes. I've been working my way through Perl books but am tired of doing exercises and want something useful to do.

Here's the full script:

#!/usr/bin/perl use strict; use warnings; my $excludes = "/home/user1/scripts/perl/backup/excluded_files.txt"; my $storageLocation = "/mnt/mount_point/dir1/"; my $archiveName = "backup.tar.gz"; my $archiveDir = "/home/user1/temp"; my @args = ("/bin/tar", "czv --exclude-from=$excludes -f", $storageL +ocation.$archiveName, $archiveDir ); system(@args) == 0 or die "system @args failed: $?";
Which produces the error:
/bin/tar: Old option `b' requires an argument. Try `/bin/tar --help' or `/bin/tar --usage' for more information. system /bin/tar czv --exclude-from=/home/user1/scripts/perl/backup/excluded_files.txt -f /mnt/mount_point/dir1/backup.tar.gz /home/user1/temp failed: 5 12 at /tmp/filename.pl line 12.

In reply to Error using system() and tar with several options by gctaylor1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.