Dear Master Monks,
This a quickie, but it's been annoying me for ages and I wanted to find out how everyone does this. It's more a filesystem permission question, but it might be solved with something that I'm not aware of using perl.
I have a cgi cd/dvd backup script, the problem being that I can't create the log files in the directories I want, as they are owned by root. I have added the apache group to them though and made them writeable for apache, but that doesn't work. I use sudo, without a password prompt for the burning of the CD/DVD etc.
Is this simpliest way just to make a new directory that is completely owned by apache?
P.S. There are a few tests missing from this too, I know.
Thanks
CGI Script:
#!/usr/bin/perl -T use strict; use warnings; require 5; $|++; use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Sendmail; use POSIX qw(strftime); # For safe ENV $ENV{PATH} = '/bin:/usr/bin'; my $to = 'ghenry@perl.me.uk, info@domain.org.uk'; my $from = '"Support Services" <support@perl.me.uk>'; my $time = localtime; my $date = strftime '%d.%m.%y', localtime; my $hostname = 'server'; my $page = new CGI; my $speed = '32'; my $imagefile = "/server-$date.iso"; my $imagedir = '/opt/backups'; my $defaultdir = '/files'; my $contentsfile = 'contents.txt'; my $device = '/dev/hda'; my $logdir = '/opt/logs'; print $page->header(), $page->start_html( -title=>'Backup Progress....', -author=>'Gavin Henry', -style=>'/bottom.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://hidded_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 into it +: $!\n"; # Create a "table of contents" file. !system "sudo ls -lRF $defaultdir > $defaultdir/$contentsfile" or die "I don't have write permission on $defaultdir,so I can't cr +eate $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 srv-$date -o $imagefile $defaultdir" 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://hidden_hostname/cgi-bin/swish.cgi" </script>'; print "\n\nISO not too big and exists. \nBurning the CDRW.\n +\n" ."\nPlease be patient, this will take a while...\n\n"; !system "sudo cdrecord -v -eject dev=$device $imagefile" + or die "There must be something wrong with the CD/DVD or there i +s no CD in the drive.\n \n\nBackup failed."; 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" ."Backup Solution brought to you by Gavin Henry.\n\n" # Delete created image unlink $imagefile or die "I can't delete the CD/DVD image: $!\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(); exit 0 } else { # print messages to screen 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() ; exit 0 }
Gavin.
In reply to Permissions for a cgi script by ghenry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |