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

sanju7:

I find the first error message surprising, as I'd expect that the line numbers reported would be lines where the code would actually try to access the files, rather than for calling File::Find's find function. I notice that you've got a prototype on your filter function, so I'd drop the parenthesis. I don't know perl well enough to know if it would/could cause that problem or not, but it's certainly not helpful.

...roboticus

  • Comment on Re^3: Remove Script for a Infrastructure file managenet system running embedded perl

Replies are listed 'Best First'.
Re^4: Remove Script for a Infrastructure file managenet system running embedded perl
by sanju7 (Acolyte) on Jul 19, 2010 at 07:53 UTC
    Dropping the parenthesis doesn't change anything. I am still not getting if the script didn't understand the path belongs to a remote share and trying to stat it locally causing the error ..?

      sanju7:

      You may want to re-read the documentation for File::Find's wanted function. You're using the $_ variable, which doesn't contain the full path name to the file(s) of interest (unless you've set the no_chdir option). So at the very least, you need to set the no_chdir flag or your subroutines would need to change.

      Other things I can think of to check:

      Is the script running under your user account, or some other account? If it's another account, perhaps that account doesn't have access to the share(s) on the other boxes.

      To test your question about whether the script understands a remote path: Check it without the rest of your program, so you can clearly determine whether or not it understands the remote path, something like:

      perl -e 'print "exists" if -e "//hostname/share-test"'

      ...roboticus

        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 ?