Roboticus:
Your leads were genuine so i made few changes in the code .#! /usr/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 $ThisSourceDirectory = q|holds the source file location |; our $ThisSourceDirectory = "/home/ssaha/tmp/source/"; #our $ThisSourceDirectory = "\\\\hostname\\share-test"; if ($ThisSourceDirectory =~ m/^\\\\/ ) { ($ThisSourceDirectory =~ s/[\\]/\\\\/g ) ; my $file ; if (($DelEmptyFoldrArchive eq "yes ")&&($ThisMoveTarget)) { if (($ThisSourceDirectory)&&("$Error" == 0)) { print STDERR "Debug3: entering check1 \n" ; find({ wanted => \&wanted, no_chdir => 1 }, $ThisSourceDirectory); sub wanted { return unless -f; $file = $_; print STDERR "$file \n " ; } if ($file) { print STDERR "Debug3: entering check2 file is file \n +" ; print STDERR "The $ThisSourceDirectory has files pres +ent \n" ; } # elsif ($file eq "") { elsif (!$file) { print STDERR "Debug3 entering check3 file is no file\n" ; finddepth (sub { rmdir $_; }, $ThisSourceDirectory); } } elsif (($ThisSourceDirectory)&&("$Error" != 0)) { print STDERR "Debug3 entering check4 \n" ; print STDERR "JOB Completed with Errors, Source Agent used was SRCHOST +\n" ; } } else { print STDERR "Debug3: entering check5 \n" ; print STDERR "DelEmptyFoldrArchive is $DelEmptyFoldrArchive, + skipping directory deletion. \n" ; }
Here activated the no_chdir flag of File::Find. Now i get the full file path. Also i tested with the shared path as well (//homename/share-dir/)type paths. Based on the observation i have applied a variable input modification to convert every shared path to (////hostname//share-dir//) type. Because given proper escape to the backslashes the code is able to stat the share paths. These are all good.
New Issue
Since last 3 days of testing shows the code is behaving differently in Windows and Linux depending upon where the agent is running them.The above code does work fine when agent run them on,
(a) windows when the path are local (C:\dir\source)type path and cleans up the directories when the source directories are empty etc.(b) But it still fails silently when agent runs them from Windows to (\\hostname\share-dir\) type paths.
(c) Also when agent is running in Linux its failing silently to remove (/usr/local/share-dir/) type paths.
A small check on all of these test conditions does detect that when code iterates through empty directory it goes through check1/3 (prints check1 and check3) i.e if operator does compare properly and brings it to the right loop, however it still doesn't do the cleaning.<\P>
Is it possible when the code iterates through empty directory and the $file becomes empty or (undef or 0) confusing the if operator and not running the rest of command on that curly brace properly ? In that case i have to test the $file variable on each time for undef or no value and null it or something i guess. What do you think ?
In reply to Re^6: Remove Script for a Infrastructure file managenet system running embedded perl
by sanju7
in thread Remove Script for a Infrastructure file managenet system running embedded perl
by sanju7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |