About the environment :

The script stays on central location but runs through an agent on remote hosts . Central server pushes the script to a scheduler on remote machines to a version of embedded perl similar to standard perl version 5.8.8 .

I wrote my script on simple concept, given a path, it walks down the directory tree from a given path ( Path could be local path like "c:\windows", "/usr/local" or shared path "\\serverhost\share" since agents on windows or linux or mac could run it) , check if any of the directories has any file present or not, then delete those directories if there is no file on them. My script only partially successful, fails on shared server paths.

Here my script part of an automation server / client program runs on remote agents (on windows , linux or mac clients) after following,

<1> Files have been copied from source ($ThisSourceDirectory ) to destination location

<2> Archive(for added security ) of the above files after the copy job from source ($ThisSourceDirectory ) to archive location($ThisMoveTarget) completes.

<3> If archive is ok then cleanup script checks certain condition and upon satisfying removes the empty directory structure from source location.

My Script

#! /usr/bin/perl -w # Testing signiant code # 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 (($DelEmptyFoldrArchive eq "yes ")&&($ThisMoveTarget)) { if (($ThisSourceDirectory)&&("$Error" == 0)) { find(\&filter, $ThisSourceDirectory); sub filter() { return unless -f; our $file = $_; print STDERR "$file \n " ; } if ($file) { print STDERR "The $ThisSourceDirectory has files pres +ent \n" ; } elsif (!$file) { finddepth (sub { 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" ; } # __END__

Short explanation

My script checks few condition:

(I) Checks if previous task was ok by Error=0 etc

(II) checks if the veriabls such as "sourceDir" , "DestinationDir" are defined etc and Yes/ No string

(III) walks down the directory tree, checks if files present at each location of given directory tree .

(IV) delete all directories which doesnt have any files present on them.

The script is tested with perl on Linux and Windows and it works from central server on agents with the embedded perl as well. However i need following help.

My Issue with this code:

It runs and removes files from windows, Linux (not tested with Mac yet --i.e not as important now)local directories however it doesn't work on shared storage path such as "\\hostname\directory\sub".

The above script when run on the embedded perl on a central server works fine but silently quits when it gets "\\servername\share" type path.

It should ideally

(I) check the source location ( mostly a uri like"\\Sharedhost\directory\source\")

(II) walks the directories down the source "\\Sharedhost\directory\source\ ... \ ... \" etc

(problem) I am not getting how to tell the script to check the ($ThisSourceDirectory) variable and depending what is there (windows style local or shared storage location or mounted directory etc like "c:\dir" or /root/dir" etc --do it straightway and if necessary (i.e "\\servername\dir" type locations) recreate the variable to differentiate hostname from share dir etc and then,

(a) connect the server share

(b)do the check and run cleanup if matches criteria

(c)then exit if ok etc

About my script: Since its an embedded version of perl its not readily accepting external modules so i refrained from using them (however all suggestions are welcome).

Making it work with shared path is an issue. Not getting how to achieve or if it need module or a c routine perhaps to do the network call to remote share host etc. If you can pinpoint and help me construct a better way, have an idea with a code snippet that you think may work would be a grateful . Thanks again for reading this far.


In reply to Remove Script for a Infrastructure file managenet system running embedded perl by sanju7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.