Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^10: Remove Script for a Infrastructure file managenet system running embedded perl

by sanju7 (Acolyte)
on Jul 22, 2010 at 22:49 UTC ( [id://850936]=note: print w/replies, xml ) Need Help??


in reply to Re^9: Remove Script for a Infrastructure file managenet system running embedded perl
in thread Remove Script for a Infrastructure file managenet system running embedded perl

Roboticus

Using $File::Find::name rather has undesired effects.
#! /usr/ddsperl/bin/perl -w # Testing # Author: #use strict; use diagnostics; use File::Find; # Variable "Error" contains any error of previous task runs. # Variable "ThisMoveTarget" contains destination archive location path +. If this stores a path (i.e if directories are archived) then # the main body of code (i.e walk down the source location for deletin +g empty directories) should execute my $Error = "0" ; # my $ThisMoveTarget = q|holds location where archive files should go +|; my $ThisMoveTarget = '/home/ssaha/tmp/archive'; # our $DelEmptyFoldrArchive = q|holds yes or no |; our $DelEmptyFoldrArchive = "yes "; # our $DelEmptyFoldrArchive = "no "; # our $ThisSourceDirectory = q|holds the source file location |; our $ThisSourceDirectory = "/home/ssaha/tmp/source/"; #our $ThisSourceDirectory = "\\hostname\share-dir"; if ($ThisSourceDirectory =~ m/^\\\\/ ) { ($ThisSourceDirectory =~ s/[\\]/\\\\/g ) ; } my $file ; if (($DelEmptyFoldrArchive eq "yes ")&&($ThisMoveTarget)) { if (($ThisSourceDirectory)&&("$Error" == 0)) { find({ wanted => \&wanted, no_chdir => 1 }, $ThisSourceDirectory); sub wanted { return unless -f; $file = $_; print STDERR "$file \n " ; } if ($file) { print STDERR "The $ThisSourceDirectory has files pres +ent \n" ; } elsif (!$file) { finddepth (sub { print " directories are $File::Find::name \n"; rmdir $File::Find::name ; # rmdir $_ ; # rmdir }, $ThisSourceDirectory); } } elsif (($ThisSourceDirectory)&&("$Error" != 0)) { print STDERR "JOB Completed with Errors, Source Agent used was SRCHOST +\n" ; } } else { print STDERR "DelEmptyFoldrArchive is $DelEmptyFoldrArchive, + skipping directory deletion. \n" ; }

When used File::Find::name with rmdir , it deletes the source directory itself ($ThisSourceDirectory=/home/ssaha/tmp/source ) upon condition being satisfied (empty directory) and not the constituent sub directories inside. The only two options i am finding safe is "rmdir $_" and "rmdir". Even though they are working as a code test on separate linux environ --on actual test script(code) is only able to delete on windows clients locally (c:\path etc format. Its not able to delete inputs such "\\hostname\share\" not even in Linux ("\usr\local\tmp") type. I think there a possibility that this is because of rmdir not getting full pathname and i am not getting how it could be achieved safely.

output

[scripts]# perl ./testArchive.pl directories are /home/ssaha/tmp/source/dir1/folder directories are /home/ssaha/tmp/source/dir1 directories are /home/ssaha/tmp/source/dir3/folder directories are /home/ssaha/tmp/source/dir3 directories are /home/ssaha/tmp/source/dir2/folder directories are /home/ssaha/tmp/source/dir2 directories are /home/ssaha/tmp/source [root@hostname scripts]# ls -l /home/ssaha/tmp/source ls: /home/ssaha/tmp/source: No such file or directory [root@nuuuniitsahalab scripts]# ls -l /home/ssaha/tmp/ total 0

Replies are listed 'Best First'.
Re^11: Remove Script for a Infrastructure file managenet system running embedded perl
by sanju7 (Acolyte) on Jul 23, 2010 at 16:17 UTC

    Roboticus:

    The solution is achieved. The issues weren't on the areas i though they would be. They were on the user input forms, the forms were not passing the values cleanly to variables. Still doing the testing but i will add more details on this matter and the final code.

    Thank you Roboticus.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://850936]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found