I have an upload script that uses rsync over ssh to upload files to my webhost (now that I've finally moved to one that gives me ssh access, woo-hoo!). I first wrote it as shell. It went something like this:

#! /bin/sh cd $(dirname $0)/site # clear out garbage find . -name '*~' | xargs rm # what do we want to sync? sync=$(ls | grep -v perllib | grep -v \\.xoops_) # what do we not want to prune remotely? remote_keep="*.ttc *.xoops_*" remote_keep=$(for x in $remote_keep; do echo "--exclude=$x"; done) # sync. rsync -avz "$@" --delete -e 'ssh -l myuser' $remote_keep $sync myhost. +com:
Where this got ugly was simply keeping the list of local excludes for uploading, and remote excludes for pruning. Those are ugly. Instead, I have:
#!/usr/bin/perl use File::Spec; use FindBin; # make sure we're in the right directory. chdir File::Spec->catdir($FindBin::Bin, 'site'); # clear out garbage. use File::Find; find( sub { /~$/ and unlink }, '.'); # directories we want to sync... my @sync = grep { -d $_ and !/perllib/ and !/\.xoops_/ } glob '*'; # remote directories we don't want to prune... my @remote_keep = map { '--exclude=' . $_ } qw(*.ttc *.xoops_*); # sync... system(#qw(/bin/echo), qw(/usr/bin/rsync -avz), @ARGV, qw(--delete -e), 'ssh -l myuser', @remote_keep, @sync, qw(mysite.com:) );
I can move the lists to the top of the script, and make it really easy to add new excludes without having to put in a bunch of --exclude='s. Meanwhile, what I have locally actually works (with the extra modules installed locally in perllib), but I don't need/want that uploaded (since there are some XS modules, I want to build them on the remote host - I have a CPAN directory that I upload, too, with all the tarballs of modules I want to use).

The shell performed adequately. The perl version uses only three processes (perl and rsync and its ssh), and is easier to add more stuff to, IMO.


In reply to Re^5: scripting tar by Tanktalus
in thread scripting tar by FredKJ

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.