#!/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 < \$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;