<quote who="JupiterHost.Net"> >>> Is it possible for me to write a perl cgi script that will echo the >>> output from an rsync backup? >> >> Sure, why not :) >> >> Sorry, had to be done ;p >> >> More info needed, code you've tried, how you're doing rsync, etc >> >> Start with: >> >> #!/usr/bin/perl >> >> use strict; >> use warnings; >> >> use CGI; >> >> print CGI::header(); >> >> print "Starting rsync...<br />\n"; > > Actually probably want to change the above two lines to: > > $|++; > > print CGI::header('text/plain'); > > print "Starting rsync...\n"; > >> # rsync code goes here >>
So far I've got this, that works fine, but there's no output on the screen when using File::Rsync. Not sure how to grab it. Oh, I still need to put more checks in this: #!/usr/bin/perl ################################################# # program: rsync.cgi # # license: GPL # # author: Gavin Henry # # company: Suretec Systems Ltd. # # url: http://www.suretecsystems.com # # version: v0.1 # # # # first draft : 27-01-05 # # last update : 28-01-05 # ################################################# $|++; # stdout hot use strict; # avoid stupid bugs use warnings; # Let us know what is bad require 5; # for follwing modules use CGI; # Use CGI stuff for web output use Mail::Sendmail; # For sending the e-mails use POSIX qw(strftime); # For the date format use File::Rsync; # Rsync Perl module my $to = '[EMAIL PROTECTED]'; my $from = '"Suretec Support Services" <[EMAIL PROTECTED]>'; my $time = localtime; my $datestamp = strftime '%d.%m.%y.%T', localtime; my $hostname = 'ndserver'; my $page = new CGI; my %ropts = ( verbose => 1, delete => 1, recursive => 1 ); my %dirs = ( src => '/home/ghenry/docbook', dest => '/home/ghenry/docbook2'); print $page->header(), $page->start_html( -title=>'Backup Progress....', -author=>'Suretec Systems Ltd.', -style=>'/suretec.css', ); print ' <div id="page"> <h3>Backup starting....</h3> <p>Please be patient....</p> <pre>'; my $bck = File::Rsync->new(\%ropts); $bck->exec(\%dirs) or warn '<h1>Backup failed</h1>'; print '</pre>'; my %mails = ( To => "$to", From => "$from", Subject => "Ad-hoc backup complete on $hostname on $time", Message => "Ad-hoc backup has been completed on $hostname" . " on $time\n" ."Backup Solution brought to you by Suretec Systems Ltd.\n\n" ."T \+44 \(0\) 1467 624141\n" ."F \+44 \(0\) 1224 742001\n" ."E [EMAIL PROTECTED]" ."W http\:\/\/support.suretecsystems.com\n\n" ."Open Source. Open Solutions\(tm\).\n\n" ."http://www.suretecsystems.com/\n" ); sendmail(%mails); # Success finish message print "\<h3\>Backup complete on $time for $hostname.\</h3\>" ."\<h3\>E-mail sent to David Cullen and Suretec with details.\</h3\>"; # Create a success logfile open LOG, ">>/opt/suretec/logs/Ad-hoc-backup-$datestamp.log" or die "Cannot create logfile: $!"; print LOG "Ad-hoc backup completed on $time for $hostname\n\nAn e-mail has been sent.\n\n" ."Backup Solution brought to you by Suretec Systems Ltd.\n\n" ."T \+44 \(0\) 1467 624141\n" ."F \+44 \(0\) 1224 742001\n" ."E [EMAIL PROTECTED]" ."W http\:\/\/support.suretecsystems.com\n\n" ."Open Source. Open Solutions\(tm\).\n\n" ."http://www.suretecsystems.com/\n\n"; close LOG; print "\<h3\>Logfile also created in \/opt\/suretec\/logs\/ on $time.\n\n"; print '</div>', $page->end_html() ; exit (0); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>