Like in my previous post I would ask you to give some feedback on my second script. This script will start a rsync process between to places. I would like to get some feedback on this script so I can improved it or maybe you see some things that can go wrong that I don't see.

Many thanks!

#!/usr/bin/perl # (c) Dieter Odeurs # This script starts rsync for a back-up job use strict; use warnings; use Getopt::Long; my $path = ""; my $destination; my $help; #Show usage sub showUsage{ print <<EOF; ---------------------------- -- Usage for rsync script -- ---------------------------- Required: --path : The source directory, this is the directory you want to back-u +p Example --path='/path/to/source' --destination This is the destination, where you want to put the back-up Example --destination='/path/to/destination' Optional:"; --exclude Use this option if you want to exclude some directories Without this option the script will exclude only .etc and lost ++found Example: --exclude='test' --exclude='demo' EOF exit; } #Without exclude options the script automatically exclude .etc and los +t+found my @exclude = ( ".etc", "lost+found" ); #You must specify a path, destination and if you want to exclude some +extra files it's possible with exclude showUsage() if (!GetOptions ( 'path=s' => \$path, 'exclude=s' => \@exclude, 'destination=s' => \$destination, 'help|?' => \$help, '<>' => \&showUsage ) or defined $help ); # Check if the path exist otherwise exit the program and give an error if(defined $path){ if (-d $path){ print $path . " is a correct path \n"; }else{ print $path . " is a incorrect path \n"; exit; } }else{ showUsage(); } # Check if a destination is defined unless (defined $destination) { showUsage (); } print "exclude : @exclude \n"; # Create the command to start rsync with all the excludes and options my $cmd = "rsync -av --iconv=iso88591,utf8 --stats"; foreach my $exclude (@exclude) { $cmd = $cmd . " --exclude '$exclude'"; } $cmd .= " $path $destination"; print $cmd . "\n"; # Run the program and show the output my @result; @result = `$cmd 2>&1`; foreach my $result (@result) { print $result; chomp $result; } #exit the program exit;


In reply to Feedback on my second script by Jackiejarvis

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.