andygates: (Default)
andygates ([personal profile] andygates) wrote2009-02-25 10:06 am
Entry tags:

Perl file test help?

i'm avoiding madness and rage by cobbling together a Perl script.  It needs to check a bunch of network files for various file characteristics (SQL server backup dumps, to be exact, by age: we have a gajillion of them and I am *not* checking them by hand).  I'm having trouble getting my Perl script (I'm a Perl newbie but it had a badger on one of the books, and I'm taking my good omens where I can get them) to find files on the network.  Any ideas?

my @file_list = ("print.gif", "..\\wWwroot\\sql_server_backups.pl", "c:\\datix.log", "\\\\cm017320\\c\$\\DATIX.log", "r:\\leaverlog.txt", "r:\\everyone_test.txt");

$output .= "\n<ol>";
foreach my $testfile (@file_list) {
  if (-e $testfile){
    $output .= "<li> $happystart $testfile exists. $happyend</li>";
  }
  else{
    $output .= "<li> $grumpystart $testfile does not exist. $grumpyend</li>";
  }
}
$output = $output . "</ol>\n";


Gives:

SQL Server Backups:

  1. print.gif exists.
  2. ..\wWwroot\sql_server_backups.pl exists.
  3. c:\datix.log exists.
  4. \\cm017320\c$\DATIX.log does not exist.
  5. r:\leaverlog.txt does not exist.
  6. r:\everyone_test.txt does not exist.

...all the files are known to be good.  File 3 is the same as file 4, only with a UNC path.  6 has explicit "everyone = Full Control" file permissions.  All machines are windows boxes, and the server is IIS running with the local system account on my box (which is cm017320).  If I try to open a network file I get 'permission denied' so I'm guessing this is a permissions-looking-over-the-network kind of issue.  


There's a pint in it  :)

calum: (Default)

[personal profile] calum 2009-02-25 11:51 am (UTC)(link)
Are you using Cygwin Perl, or Perl for Windows (Active Perl)? It shouldnt matter, but it might.

Why are you using -e? You care if the file exists, but not if you have access to it? You tried using -r (for readable)?

I'm wondering if there is some sort of quirk about access to the directories the files are contained in.. Perl probably read the directory rather than the file to check if it exists.

The other thing you can try, is to actually open the file - and see if that fails.

[identity profile] andygates.livejournal.com 2009-02-25 11:53 am (UTC)(link)
Actually, the thing I care about is the file's age. That's -M, right? I was just using -e because it was the first file test in the "File tests for noobs" list :)

Opening the files fails with access-denied, even for the Everyone:Full one and the one that's local. ActivePerl.
calum: (Default)

[personal profile] calum 2009-02-25 11:57 am (UTC)(link)
My primary recommendation is.. Use python. Its a nice clear language that doesnt have 2000 ways of doing everything :)

But aside from that, let me try running that in a similar setup here and see whether I can reproduce your problem.
calum: (Default)

[personal profile] calum 2009-02-25 12:20 pm (UTC)(link)
OK, have tried your code on my machine.. and it works just fine.. with local files, full paths, network drives etc.

So, its not your perl thats weird.. its your file or directory permissions somehow.


[identity profile] andygates.livejournal.com 2009-02-25 02:10 pm (UTC)(link)
Cool, ta!

(Isn't Python the thing that enables programmers to fly?)
calum: (Default)

[personal profile] calum 2009-02-25 02:24 pm (UTC)(link)
import antigravity

(yes)

:)

[identity profile] andygates.livejournal.com 2009-02-25 02:43 pm (UTC)(link)
Chortle!

Heh - my script works just fine if I run it from the command line. It's definitely a webserver-permissions issue. Cheers again.

[identity profile] andygates.livejournal.com 2009-02-25 06:08 pm (UTC)(link)
FYI, after abandoning that silly IIS and discovering the Joy of Glob, the proof-of-concept stuff worked perfectly at close of play. That'll save the backup monkeys about 4h a day (!) and give the auditors a record, too, so the Babycham's on me when I'm next up.
calum: (Default)

[personal profile] calum 2009-02-25 06:17 pm (UTC)(link)
Yay... Will be glad to see you no matter who is buying though

[identity profile] ravenbait.livejournal.com 2009-02-25 07:09 pm (UTC)(link)
Which is when, incidentally?

HINT.