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:
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:#! /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:
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).#!/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:) );
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |