-- 
Just getting into the best language ever...
Fancy a [EMAIL PROTECTED] Just ask!!!

<quote who="Chris Devers">
> On Thu, 27 Jan 2005, Gavin Henry wrote:
>
>> my rsync.cgi script that I was taking about earlier, when run via
>> cgi-bin,
>> ps- aux soshow three copies of the same command.
>>
>> Does a cgi process fork 3 times, or is this an apache feature?
>
> No, and no.
>
> Of course, there must be a reason that it's happening in this case, but
> without seeing the source, it's hard to say why it's happening.
>

It's below. I wanted to use File::Rsync, but I couldn't figure out how to
get the output of the command.

#!/usr/bin/perl

$|++;                           # 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        = '"Support Services" <[EMAIL PROTECTED]>';
my $time        = localtime;
my $datestamp   = strftime '%d.%m.%y.%T', localtime;
my $hostname    = 'testserver';
my $page        = new CGI;
my $rsync       = '/usr/bin/rsync';
my $option1     = '-v';
my $option2     = '--delete';
my $option3     = '-r';
my $origdir     = '/orig';
my $todir       = '/new';
my $logdir      = '/orig';

my @args        = ( $option1, $option2, $option3, $origdir, $todir );
#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=>'Support Ltd.',
                -style=>'/support.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>';

my $bdata = `$rsync @args`;
print "$bdata";

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,
with the command:\n\n$rsync @args\n\nOutput: \n\n$bdata\n\n"
                . " The commands output was: \n\n$bdata\n\n"
                ."Backup Solution brought to you by Support Ltd.\n\n"
);
sendmail(%mails);

open LOG, ">>$logdir/Ad-hoc-backup-$datestamp.log"
  or die "Cannot create logfile: $!";
print LOG
        "Ad-hoc backup has been completed on $time for $hostname, with the
command:\n\n$rsync @args\n\nOutput: \n\n$bdata\n\nAn e-mail has been
sent.\n\n"
         . " The commands output was: \n\n$bdata\n\n"
         ."Backup Solution brought to you by Support Ltd.\n\n";
close LOG;

# Success finish message
print "\<h3\>Backup complete on $time for $hostname.\<\/h3\>"
      ."\<p\>E-mail sent to Support with details.\<\/p\>"
      ."\<p\>Logfile also created in $logdir on $time.\<\/p\>"
      ."\<\/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>


Reply via email to