--- loncom/debugging_tools/move_construction_spaces.pl 2011/10/26 14:19:42 1.1 +++ loncom/debugging_tools/move_construction_spaces.pl 2011/10/27 03:43:53 1.4 @@ -1,8 +1,35 @@ #!/usr/bin/perl # +# The LearningOnline Network +# # Move Construction Spaces from /home/$user/public_html # to /home/httpd/html/priv/$domain/$user and vice versa -# +# +# $Id: move_construction_spaces.pl,v 1.4 2011/10/27 03:43:53 raeburn Exp $ +# +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# +################################################# use strict; use lib '/home/httpd/lib/perl/'; @@ -12,40 +39,128 @@ use Apache::lonlocal; use File::Copy; use GDBM_File; - -my ($parameter)=(@ARGV); my $lang = &Apache::lonlocal::choose_language(); &Apache::lonlocal::get_language_handle(undef,$lang); -print"\n"; -# Abort if more than one argument. -if (@ARGV > 1) { - print &mt('usage: [_1]','move_construction_spaces.pl [move|undo]')."\n\n". - &mt('You should enter either no arguments, or just one argument -- either move or undo.')."\n". - &mt("move - to move authors' Construction Spaces from: /home to /home/httpd/html/priv/domain")."\n". - &mt('undo - to reverse those changes and move Construction Spaces back from: /home/httpd/html/priv/domain to /home')."\n". - &mt('no argument to do a dry run of the move option, without actually moving anything.')."\n"; +if ($< != 0) { + print &mt('You must be root in order to move Construction Spaces.')."\n". + &mt('Stopping')."\n"; exit; } -print "\nMoving authors' Construction Spaces\n". - "-----------------------------\n\n". - "If run without an argument, the script will report what it would do\n". - "when moving Construction Spaces from /home to /home/httpd/html/priv/.\n\n". - "If there are ambiguities (i.e., the same username belongs to two domains)\n". - "this will be flagged, and you will be able to decide how to proceed.\n"; - my $perlvar=&LONCAPA::Configuration::read_conf(); -my ($lonuserdir,$londocroot); +my ($lonuserdir,$londocroot,$londaemons); if (ref($perlvar) eq 'HASH') { $lonuserdir = $perlvar->{'lonUsersDir'}; $londocroot = $perlvar->{'lonDocRoot'}; + $londaemons = $perlvar->{'lonDaemons'}; } undef($perlvar); +if ($lonuserdir eq '') { + print &mt('Could not determine location of [_1] directory.',"'lonUsersDir'")."\n". + &mt('Stopping')."\n"; + exit; +} + +if ($londocroot eq '') { + print &mt('Could not determine location of [_1] directory.',"'lonDocRoot'")."\n". + &mt('Stopping')."\n"; + exit; +} + +my $distro; +if ($londaemons eq '') { + print &mt('Could not determine location of [_1] directory.',"'lonDaemons'")."\n". + &mt('Stopping')."\n"; + exit; +} else { + if (-e "$londaemons/distprobe") { + if (open(PIPE,"perl $londaemons/distprobe|")) { + $distro = ; + close(PIPE); + } + } +} + +if ($distro eq '') { + print &mt('Could not determine Linux distro.')."\n". + &mt('Stopping')."\n"; + exit; +} else { + my $stopapachecmd = '/etc/init.d/httpd stop'; + my $apacheprocess = '/usr/sbin/httpd'; + my $stopapachecmd = '/etc/init.d/httpd stop'; + my $proc_owner = 'root'; + if ($distro =~ /^(suse|sles)/) { + if ($distro =~ /^(suse|sles)9/) { + $stopapachecmd = '/etc/init.d/apache stop'; + } else { + $apacheprocess = '/usr/sbin/httpd2'; + $stopapachecmd = '/etc/init.d/apache2 stop'; + } + } elsif ($distro =~ /^(?:debian|ubuntu)(\d+)/) { + $apacheprocess = '/usr/sbin/apache2'; + $stopapachecmd = '/etc/init.d/apache2 stop'; + } elsif ($distro =~ /^(?:fedora)(\d+)/) { + my $version = $1; + if ($version >= 16) { + $stopapachecmd = '/bin/systemctl stop httpd.service'; + } + } + if (open(PIPE,"ps -ef |grep '$apacheprocess' |grep -v grep 2>&1 |")) { + my $status = ; + close(PIPE); + chomp($status); + if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) { + print "\n". + &mt('You need to stop the Apache daemon before moving Construction Spaces.')."\n". + &mt('To do so use the following command: [_1]',"\n\n$stopapachecmd")."\n\n". + &mt('Now stopping the move_construction_spaces.pl script.')."\n"; + exit; + } + } else { + print &mt('Could not determine if Apache daemon is running.')."\n"; + } +} + +my $stoploncontrol = '/etc/init.d/loncontrol stop'; +if (open(PIPE,"ps -ef |grep lond |grep -v grep 2>&1 |")) { + my $status = ; + close(PIPE); + chomp($status); + if ($status =~ /^www\s+\d+\s+/) { + print "\n". + &mt('You need to stop the LON-CAPA daemons before moving Construction Spaces.')."\n". + &mt('To do so use the following command: [_1]',"\n\n$stoploncontrol")."\n\n". + &mt('Now stopping the move_construction_spaces.pl script.')."\n"; + exit; + } +} + +# Abort if more than one argument. + my $parameter=$ARGV[0]; $parameter =~ s/^\s+//; $parameter =~ s/\s+$//; + +if ((@ARGV > 1) || (($parameter ne '') && ($parameter !~ /^(move|undo)$/))) { + print &mt('usage: [_1]','move_construction_spaces.pl [move|undo]')."\n\n". + &mt('You should enter either no arguments, or just one argument -- either move or undo.')."\n". + &mt("move - to move authors' Construction Spaces from: [_1] to [_2].", + "'/home'","'$londocroot/priv/'")."\n". + &mt('undo - to reverse those changes and move Construction Spaces back from: [_1] to [_2].', + "'$londocroot/priv/'","'/home'")."\n". + &mt('no argument to do a dry run of the move option, without actually moving anything.')."\n"; + exit; +} + +print "\n".&mt("Moving authors' Construction Spaces.")."\n". + "-----------------------------\n\n". + &mt('If run without an argument, the script will report what it would do when moving Construction Spaces from [_1] to [_2].', + "'/home'","'$londocroot/priv/'")."\n\n". + &mt('If there are ambiguities (i.e., the same username belongs to two domains), this will be flagged, and you will be able to decide how to proceed.')."\n"; + my (undef,undef,$uid,$gid) = getpwnam('www'); my ($action) = ($parameter=~/^(move|undo)$/); if ($action eq '') { @@ -53,22 +168,45 @@ if ($action eq '') { } if ($action eq 'dryrun') { - print "\nRunning in exploratory mode.\n". - "Run with parameter 'move' to actually move the author spaces, i.e. \n". - "move_construction_spaces.pl move\n\n". - "Run with parameter 'undo' to move author spaces back to /home, i.e. \n". - "move_construction_spaces.pl undo\n\n"; + print "\n". + &mt('Running in exploratory mode ...')."\n\n". + &mt('Run with argument [_1] to actually move Construction Spaces to [_2], i.e., [_3]', + "'move'","'$londocroot/priv'","\n\nperl move_construction_spaces.pl move")."\n\n\n". + &mt('Run with argument [_1] to move Construction spaces back to [_2], i.e., [_3]', + "'undo'","'/home'","\n\nperl move_construction_spaces.pl undo")."\n\n\n". + &mt('Continue? ~[y/N~] '); + if (!&get_user_selection()) { + exit; + } else { + print "\n"; + } } else { - print "\n *** Running in a mode where changes will be made.\n"; + print "\n *** ".&mt('Running in a mode where changes will be made.')." ***\n"; if ($action eq 'move') { - print "\nMode is $action -- directories will be moved to $londocroot/priv\n"; + print "\n". + &mt('Mode is [_1] -- directories will be moved to [_2].', + "'$action'","'$londocroot/priv'")."\n"; } else { - print "\nMode is $action -- directories will be moved back to /home\n"; + print "\n". + &mt('Mode is [_1] -- directories will be moved back to [_2].', + "'$action'","'/home'")."\n"; } print &mt('Continue? ~[y/N~] '); - if (!&get_user_selection()) { exit; + } else { + print "\n"; + } +} + +my $logfh; +if ($action ne 'dryrun') { + if (!open($logfh,">>$londaemons/logs/move_construction_spaces.log")) { + print &mt('Could not open log file: [_1] for writing.', + "'$londaemons/logs/move_construction_spaces.log'")."\n". + &mt('Stopping.')."\n"; + } else { + &start_logging($logfh,$action); } } @@ -77,27 +215,40 @@ my %allauthors; my %pubusers; if ($action eq 'move') { + my $output; if (-d "$londocroot/priv") { - print "New Construction Spaces directory: '$londocroot/priv' already exists.\n"; + $output = &mt('New Construction Spaces directory: [_1] already exists.', + "'$londocroot/priv'")."\n"; + print $output; + print $logfh $output; } else { - print "\nCreating new directory: '$londocroot/priv' for Construction Spaces.\n"; - if (mkdir("$londocroot/priv",0755)) { + $output = &mt('Creating new directory: [_1] for Construction Spaces.', + "'$londocroot/priv'")."\n"; + if (mkdir("$londocroot/priv",0750)) { if (chown($uid,$gid,"$londocroot/priv")) { - print "Creation Successful\n"; + $output .= &mt('Creation Successful')."\n"; + print $output; + print $logfh $output; } else { - print "Failed to changer ownership to $uid:$gid\n"; + $output .= &mt('Failed to change ownership to [_1].',"'$uid:$gid'")."\n"; + print $output; + &stop_logging($logfh,$output); + print &mt('Stopping')."\n"; exit; } } else { - print "Failed to create directory\n"; - exit; + $output .= &mt('Failed to create directory [_1].',"'$londocroot/priv'")."\n"; + print $output; + &stop_logging($logfh,$output); + print &mt('Stopping')."\n"; + exit; } } } my @machinedoms; if ($lonuserdir) { - my $dir; + my ($dir,$output); if (opendir($dir,$lonuserdir)) { my @contents = (grep(!/^\.{1,2}$/,readdir($dir))); foreach my $item (@contents) { @@ -107,18 +258,24 @@ if ($lonuserdir) { unless (grep(/^\Q$domain\E$/,@machinedoms)) { push(@machinedoms,$domain); } - my $dom_target="/home/httpd/html/priv/$domain"; + my $dom_target="$londocroot/priv/$domain"; if ($action eq 'move') { if (!-e $dom_target) { if (mkdir($dom_target,0755)) { chown($uid,$gid,$dom_target); - print "Made $dom_target\n"; + $output = &mt('Made [_1].',"'$dom_target'")."\n"; + print $output; + print $logfh $output; } else { - print "Failed to make $dom_target. Stopping\n"; + $output = &mt('Failed to make [_1].',"'$dom_target'")."\n"; + print $output; + print $logfh $output; + &stop_logging($logfh,$output); + print &mt('Stopping')."\n"; exit; } } elsif ($action eq 'dryrun') { - print "Would make $dom_target\n"; + print &mt('Would make [_1].',"'$dom_target'")."\n"; } } my %authors=(); @@ -128,7 +285,7 @@ if ($lonuserdir) { $dbref=&LONCAPA::locking_hash_tie($fname,&GDBM_READER()); } if (!$dbref) { - print "Unable to tie to $fname"; + print &mt('Unable to tie to [_1].',"'$fname'")."\n"; } elsif (ref($dbref) eq 'HASH') { foreach my $key (keys(%{$dbref})) { $key = &unescape($key); @@ -143,7 +300,10 @@ if ($lonuserdir) { } closedir($dir); } else { - print "Could not open $lonuserdir. Stopping\n"; + $output = &mt('Could not open [_1].',"'$lonuserdir'")."\n"; + print $output; + &stop_logging($logfh,$output); + print &mt('Stopping')."\n"; exit; } } @@ -193,28 +353,40 @@ if ($action eq 'undo') { foreach my $uname (keys(%privspaces)) { if (ref($privspaces{$uname}) eq 'ARRAY') { if (@{$privspaces{$uname}} > 1) { - print "Same username used for authors in multiple domains\n". - "This configuration is not supported where Construction Spaces are located in /home.\n". - "You will be able to move files for just one of the domains, choose which one: \n". - "The domains to choose from are: ".join(', ',@{$privspaces{$uname}})."\n". - "Enter choice: "; + my $displaydoms = join(', ',@{$privspaces{$uname}}); + print &mt('Same username used for authors in multiple domains.')."\n". + &mt('This configuration is not supported where Construction Spaces are located in [_1].','/home').".\n". + &mt('You will be able to move files for just one of the domains, choose which one.')."\n". + &mt('The domains to choose from are: [_1].',"'$displaydoms'")."\n". + &mt('Enter choice: '); my $choice=; chomp($choice); if (grep(/^\Q$choice\E$/,@{$privspaces{$uname}})) { - &move_priv_to_home($londocroot,$uname,$choice); + my $output = &move_priv_to_home($londocroot,$uid,$gid,$uname,$choice); + print $output; + print $logfh $output; } else { - print "Invalid choice of domain: $choice\n". - "Skipping this user: $uname\n"; + print &mt('Invalid choice of domain:')." $choice\n"; + my $output = &mt('Skipping this user: [_1].',"'$uname'")."\n"; + print $output; + print $logfh $output; next; } } elsif (@{$privspaces{$uname}} == 1) { - &move_priv_to_home($londocroot,$uname,$privspaces{$uname}[0]); + my $output = &move_priv_to_home($londocroot,$uid,$gid,$uname,$privspaces{$uname}[0]); + print $output; + print $logfh $output; } else { - print "User $uname found in $londocroot/priv was not within a domain\n"; + print &mt('Username [_1] found in [_2] was not within a domain', + "'$uname'","'$londocroot/priv'")."\n"; + my $output = &mt('Skipping this user: [_1].',"'$uname'")."\n"; + print $output; + print $logfh $output; } } } - print "Done\n"; + &stop_logging($logfh); + print "\n".&mt('Done')."\n"; exit; } @@ -222,11 +394,11 @@ if ($action eq 'undo') { if (opendir(my $dir,"/home")) { foreach my $item (grep(!/^\.{1,2}$/,readdir($dir))) { next if ($item eq 'www'); - if (-d "/home/$item") { + if ((-d "/home/$item") && ($item ne '')) { # Is there a public_html-directory? if (-d "/home/$item/public_html") { my $author = $item; - my ($domain,$skipped); + my ($domain,$skipped,$output); if (ref($pubusers{$author}) eq 'ARRAY') { ($domain,$skipped) = &choose_domain($action,$author,$pubusers{$author}); } @@ -235,49 +407,107 @@ if (opendir(my $dir,"/home")) { ($domain,$skipped) = &choose_domain($action,$author,$allauthors{$author}); } } + my $source_path="/home/$author/public_html"; if ($domain) { - my $source_path="/home/$author/public_html"; my $target_path="$londocroot/priv/$domain/$author"; if ($action eq 'move') { - move($source_path,$target_path); + if (move($source_path,$target_path)) { chown($uid,$gid,$target_path); - chmod($target_path,0755); - print "Moved $source_path to $target_path\n"; + chmod($target_path,0750); + $output = &mt('Moved [_1] to [_2].', + "'$source_path'","'$target_path'")."\n"; + my (undef,undef,$userid,$groupid) = getpwnam($author); + if ($userid eq '' && $groupid eq '' && $author ne '') { + &check_for_restore_files($londaemons,$author,$domain); + if (opendir(my $homedir,"/home/$author")) { + my @contents = + grep(!/^\.{1,2}$/,readdir($homedir)); + if (@contents == 0) { + if (rmdir("/home/$author/")) { + $output .= &mt('Removed empty directory: [_1]', + "'/home/$author/'")."\n"; + } else { + $output .= &mt('Failed to remove directory: [_1]', + "'/home/$author/'")."\n"; + } + } else { + $output .= &mt('Not removing directory [_1] as it still contains: [_2]', + "'/home/$author/'", + "\n".join("\n",@contents)."\n"); + } + } + } else { + $output .= &mt('Not removing directory [_1] for UNIX user account', + "'/home/$author/'")."\n"; + } + } else { + $output = &mt('Failed to move [_1] to [_2].', + "'$source_path'","'$target_path'")."\n"; + } + print $output; + print $logfh $output; } elsif ($action eq 'dryrun') { - print "Would move $source_path to $target_path\n"; + print &mt('Would move [_1] to [_2].',"'$source_path'","'$target_path'")."\n"; + } + } elsif ($skipped) { + if ($action ne 'dryrun') { + print $logfh &mt('Skipping this user: [_1].',"'$author'")."\n"; } - } elsif (!$skipped) { - print "*** WARNING: $author has no domain.\n". - "Enter 1: do nothing, continue\n". - "Enter 2: stop\n". - "or enter domain for user to be placed into\n". - "Your input: "; + } else { + print '*** '.&mt('WARNING: [_1] has no domain.',"'$author'")."\n". + &mt('Enter [_1]: do nothing, continue.','1')."\n". + &mt('Enter [_2]: stop.','2')."\n". + &mt('or enter domain for user to be placed into')."\n". + &mt('Your input: '); my $choice=; chomp($choice); - next if ($choice ==1); - if ($choice == 2) { print "Stopped.\n"; exit; } + if ($choice ==1) { + print $logfh &mt('Skipping -- no domain for user: [_1].',"'$author'")."\n"; + } + if ($choice == 2) { + print &mt('Stopped.')."\n"; + if ($action ne 'dryrun') { + my $output = &mt('Stopped by user because of author without domain: [_1].', + "'$author'")/"\n"; + &stop_logging($logfh,$output); + } + exit; + } if ($choice =~ /^$match_domain$/) { my $dompath="$londocroot/priv/$choice"; my $newpath="$londocroot/priv/$choice/$author"; unless (-e $dompath) { - print "*** WARNING: $dompath does not yet exist.\n"; + print '*** '.&mt('WARNING: [_1] does not yet exist.',"'$dompath'")."\n"; } if ($action eq 'move') { - print "Making author $author in domain $choice\n"; unless (-e $dompath) { - print "Making $dompath\n"; - mkdir($dompath,0755); - chown($uid,$gid,$dompath); + $output .= &mt('Making [_1].',"'$dompath'")."\n"; + if (mkdir($dompath,0755)) { + chown($uid,$gid,$dompath); + } + } + if (-e $dompath) { + if (move($source_path,$newpath)) { + chown($uid,$gid,$newpath); + chmod($newpath,0750); + $output = &mt('Moved [_1] to [_2].', + "'$source_path'","'$newpath'")."\n"; + } else { + $output = &mt('Failed to move [_1] to [_2].', + "'$source_path'","'$newpath'")."\n"; + } + print $output; + print $logfh $output; + } else { + $output = &mt('Failed to move [_1] to [_2] -- missing [_3].', + "'$source_path'","'$newpath'","'$dompath'")."\n"; } - print "Making $newpath\n"; - mkdir($newpath,0755); - chown($uid,$gid,$newpath); } elsif ($action eq 'dryrun') { - print "Would make author $author in domain $choice\n"; + print &mt('Would make author [_1] in domain [_2].',"'$author'","'$choice'")."\n"; unless (-e $dompath) { - print "Would make $dompath\n"; + print &mt('Would make [_1].',"'$dompath'")."\n"; } - print "Would make $newpath\n"; + print &mt('Would make [_1].',"'$newpath'")."\n"; } } } @@ -285,22 +515,25 @@ if (opendir(my $dir,"/home")) { } } } -print "\nDone.\n"; +if ($action ne 'dryrun') { + &stop_logging($logfh); +} +print "\n".&mt('Done.')."\n"; sub choose_domain { my ($action,$author,$domarrayref) = @_; my ($domain,$skipped); if (ref($domarrayref) eq 'ARRAY') { if (@{$domarrayref} > 1) { - print "*** ERROR: $author found in multiple domains\n". - "Enter a number to choose what action to take\n"; + print '*** '.&mt('ERROR: [_1] found in multiple domains.',"'$author'")."\n". + &mt('Enter a number to choose what action to take.')."\n"; my $num = 1; for (my $i=0; $i<@{$domarrayref}; $i++) { - print "To use: $domarrayref->[$i] enter $num\n"; + print &mt('To use: [_1] enter [_2].',$domarrayref->[$i],$num)."\n"; $num ++; } - print "To skip this user enter: $num\n". - "Your choice: "; + print &mt('To skip this user enter: [_1].',$num)."\n". + &mt('Your choice:').' '; my $choice=; chomp($choice); if ($choice =~ /^\d+$/) { @@ -309,45 +542,51 @@ sub choose_domain { } elsif (($choice < $num) && ($choice > 0)) { $domain = $domarrayref->[$choice-1]; } else { - print "Invalid choice\n"; + print &mt('Invalid choice:')." $choice\n"; $skipped = 1; } } else { - print "Invalid choice\n"; + print &mt('Invalid choice:')." $choice\n"; $skipped = 1; } } elsif (@{$domarrayref} == 1) { $domain = $domarrayref->[0]; - if ($action eq 'dryrun') { - print "Would use domain: $domain for author: $author\n"; - } } } return ($domain,$skipped); } sub move_priv_to_home { - my ($londocroot,$uname,$domain) = @_; + my ($londocroot,$uid,$gid,$uname,$domain) = @_; + my $output; if ($uname =~ /^$match_username$/ && $domain =~ /^$match_domain$/) { my $source_path="$londocroot/priv/$domain/$uname"; my $target_path="/home/$uname/public_html"; if (!-e "/home/$uname") { - if (mkdir("/home/$uname",0755)) { - chown($uid,$gid,"/home/$uname"); + my (undef,undef,$userid,$groupid) = getpwnam($uname); + if (mkdir("/home/$uname",0750)) { + if ($userid ne '' && $groupid ne '') { + chown($userid,$groupid,"/home/$uname"); + } } else { - print "Failed to create directory /home/$uname -- not moving $source_path\n"; + $output = &mt('Failed to create directory [_1] -- not moving [_2].', + "'/home/$uname'","'$source_path'")."\n"; + return $output; } } - if (!-e $target_path) { - move($source_path,$target_path); - chown($uid,$gid,$target_path); - chmod($target_path,0755); - print "Moved $source_path to $target_path\n"; - } else { - print "Directory $target_path already exists -- not moving $source_path\n"; + if (-e "/home/$uname") { + if (!-e $target_path) { + move($source_path,$target_path); + chown($uid,$gid,$target_path); + chmod($target_path,2770); + $output = &mt('Moved [_1] to [_2].',"'$source_path'","'$target_path'")."\n"; + } else { + $output = &mt('Directory [_1] already exists -- not moving [_2].', + "'$target_path'","'$source_path'")."\n"; + } } } - return; + return $output; } sub get_user_selection { @@ -369,3 +608,66 @@ sub get_user_selection { return $do_action; } +sub start_logging { + my ($fh,$action) = @_; + my $start = localtime(time); + print $fh "*****************************************************\n". + &mt('[_1] - mode is [_2].', + 'move_construction_spaces.pl',"'$action'")."\n". + &mt('Started -- time: [_1]',$start)."\n". + "*****************************************************\n\n"; + return; +} + +sub stop_logging { + my ($fh) = @_; + my $end = localtime(time); + print $fh "*****************************************************\n". + &mt('Ended -- time: [_1]',$end)."\n". + "*****************************************************\n\n\n"; + close($fh); + return; +} + +sub check_for_restore_files { + my ($londaemons,$author,$domain) = @_; + if (opendir(my $homedir,"/home/$author")) { + my @contents = grep(!/^\.{1,2}$/,readdir($homedir)); + if (@contents > 0) { + if (grep(/^restore_\d+\.sh$/,@contents)) { + if (!-e "$londaemons/logs/moved_construction_spaces") { + mkdir("$londaemons/logs/moved_construction_spaces",0755); + } + if (!-e "$londaemons/logs/moved_construction_spaces/$domain") { + mkdir("$londaemons/logs/moved_construction_spaces/$domain",0755); + } + if (-e "$londaemons/logs/moved_construction_spaces/$domain") { + if (open(my $restorefh,">>$londaemons/logs/moved_construction_spaces/$domain/$author")) { + foreach my $item (@contents) { + if ($item =~ /^restore_\d+\.sh$/) { + my @stats = stat("/home/$author/$item"); + my $lastmod = $stats[9]; + if (open(my $fh,") { + print $restorefh $_; + } + print $restorefh + "*******************************\n\n"; + close($fh); + unlink("/home/$author/$item"); + } + } + } + close($restorefh); + } + } + } + } + } + return; +} +