I'll answer my own question ;-)
I tried it and it worked!
For your info:
#!/usr/bin/perl -T use strict; # avoid stupid bugs use warnings; # Let us know what is bad require 5; # for following modules $|++; # send stuff to output asap. use CGI; # Use CGI stuff for web output use CGI::Carp qw(fatalsToBrowser); # For better error messages use Mail::Sendmail; # For sending the e-mails use POSIX qw(strftime); # For the date format # For safe ENV $ENV{PATH} = '/bin:/usr/bin'; my $to = 'me@me.com'; my $from = 'me@me.com'; my $time = localtime; my $date = strftime '%d.%m.%y', localtime; my $hostname = 'servername'; my $page = new CGI; my $speed = '32'; my $imagefile = "servername-$date.iso"; my $imagedir = '/opt/backups'; my $defaultdir = '/files'; my $contentsfile = 'contents.txt'; my $device = '/dev/hda'; my $logdir = '/var/logs'; print $page->header(), $page->start_html( -title=>'Backup Progress....', -author=>'me.', -style=>'/style.css', ); print ' <script language="JavaScript"> var x=window.confirm("Are you sure you want to run the backup to CD/DV +D?") if (!x) window.location="http://hostname/cgi-bin/swish.cgi" </script> <div id="page"> <h3>CD/DVD Backup starting....</h3> <h3>Please be patient, as this will take a long time.</h3> <pre>'; # Move into the backup dir chdir "$imagedir" or die "Either that directory doesn't exist or I can't get int +o it: $!\n"; # Create a "table of contents" file. !system "sudo ls -lRF $defaultdir > $defaultdir/$contentsfile" or warn "I don't have write permission on $defaultdir,so I can +'t create $contentsfile!\n\n Moving on....\n"; # The "l" option gives a "long" file listing. # The "R" option makes the listing recursive. # The "F" option marks the file types (directories get a trailing /). print "Creating ISO9660 file system image ($imagefile).\n"; !system "sudo mkisofs -J -l -R -V srvnme-$date -o $imagefile $defaultd +ir" or die "I can't create the image.\n"; # Wipe the inserted CDRW # echo "Blanking current CDRW" # cdrecord blank=fast dev=$DEVICE # Burn the CDRW. if (-s "$imagefile" < 700_000_000 and -e "$imagefile") { print '<script language="JavaScript"> var x=window.confirm("Is there a CD/DVD in the drive?" +) if (!x) window.location="http://hostname/cgi-bin/swish.cgi" </script>'; print "\n\nISO not too big and exists. \nBurning the CDR +W.\n\n" ."\nPlease be patient, this will take a while...\n\n"; system "sudo cdrecord -v -eject dev=$device $imagefile"; + } ( $? == 0 ) ? &success($date, $time, $hostname, $logdir, $to, $from) : &failure($date, $time, $hostname, $logdir, $to, $from); ########################## sub success { ########################## my ($date, $time, $hostname, $logdir, $to, $from) = @_; print ' <script> window.alert("Backup complete!") </script>'; # create success logfile open LOG, ">>$logdir/cdbackup-success-$date.log" or die "Cannot create logfile: $!"; print LOG "CD/DVD backup successful on $time for $hostname.\n\n"; close LOG; #send success e-mail my %mail_success = ( To => "$to", From => "$from", Subject => "CD/DVD backup complete on $hostname on $time", Message => "CD/DVD backup has been a success on $hostname +on $time\n\n"; ); sendmail(%mail_success); print "\<h3\>CD/DVD Backup complete on $time for $hostname.\<\ +/h3\>" ."\<p\>E-mail sent with details.\<\/p\>" ."\<p\>Logfile also created in $logdir on $time.\<\/p\>" ."\<\/div\>"; $page->end_html(); } ########################## sub failure { ########################## my ($date, $time, $hostname, $logdir, $to, $from) = @_; print "Oops! The ISO file is way too big. You need a DVD disc, + not a CDRW: $!\n"; # create failed logfile open LOG, ">>$logdir/cdbackup-failure$date.log" or die "Cannot create logfile: $!"; print LOG "CD/DVD backup has failed on $time for $hostname.\n\n" ."There must be something wrong with the CD/DVD media: $!\n"; close LOG; #send failure e-mail my %mail_failure = ( To => "$to", From => "$from", Subject => "CD/DVD backup failed on $hostname on $time", Message => "CD/DVD backup has failed on $hostname on $time +\n\n";); sendmail(%mail_failure); # Failure message print "\<h3\>CD/DVD Backup failed on $time for $hostname.\<\/h3\>" ."\<p\>E-mail sent with details.\<\/p\>" ."\<p\>Logfile also created in $logdir on $time.\<\/p\>" ."\<\/div\>"; $page->end_html(); }
In reply to Re^3: Control Structures
by ghenry
in thread Control Structures
by ghenry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |