accessdenied has asked for the wisdom of the Perl Monks concerning the following question:

I have simple script: my $file="/path/to/file"; if ( -f $file ) { print "DEBUG: file exists\n"; } else { print "DEBUG: no such file\n"; } I have mentioned file in place and see printout "file exists" on script execution. But all changes if I run script using sudo. Just "sudo ./script" and see another printout - "no such file"! I don't have an idea why behavior so different for my user account and for root. What is the matter?
  • Comment on Wrong file check while running using sudo

Replies are listed 'Best First'.
Re: Wrong file check while running using sudo
by moritz (Cardinal) on Nov 14, 2008 at 10:13 UTC
    You might get a better error message by trying to open a file:
    open my $handle, '<', $file or die $!;

    There are configurations where root isn't allowed to view some directories (for example with selinux) where -e would return false. But that's pure speculation on my side.

      I found root cause. In /path/to/file one folder is not readable for others and root is not in the same group as folder owner, so root can't read folder content. So simple but I had broken my brine during two last days.