crazy-duck has asked for the wisdom of the Perl Monks concerning the following question:

How to check and send an email alert if a particular file is modified or missing on windows server using a perl script

File name & path C:\Documents and Settings\username\myfile.properties

  • Comment on How to check if a file is modified or missing on windows server using a perl script

Replies are listed 'Best First'.
Re: How to check if a file is modified or missing on windows server using a perl script
by SuicideJunkie (Vicar) on Nov 01, 2013 at 16:51 UTC

    -e $filePathAndName will tell you if it exists. To determine if it has changed, you need to have something to compare it to. If you have a backup, you can compare the two files byte by byte to see if they are identical.

Re: How to check if a file is modified or missing on windows server using a perl script
by Laurent_R (Canon) on Nov 01, 2013 at 17:12 UTC

    A checksum on the file should be sufficient to figure out if the content has changed (provided the checksum of the previous version has been stored somewhere).

      Checksum is probably good enough (1/256 chance of undetected change if done as an 8 bit ASCII checksum) especially if you also check file size. A CRC module would probably give you even more accurate results if you need to be that specific.

        Yes, checking the file size (and also last modification time) certainly adds quite a bit of reliability (and is fast), and that alone may actually be sufficient for the purposes of crazy-duck, but when I mentioned checksum, I used the word as a general term for describing the overall techniques of digital "footprints", digests or signatures. I am using on some of my platforms "checksum" utilities actually implementing a CRC-32 algorithm, where the chances of undetected change are 1 in billions (at least in theory).