0

I have a very mysterious problem with bash and/or perl. I'll try to describe the behaviour.

Running a perl script via

./perlscript.pl

gives me a permission denied message.

(I am the owner of the file and the path to it -from my home dir and the file contains #!/usr/bin/perl and is executable -rwxr-xr-x )

Running the script like this:

perl perlscript.pl

is ok...

Can anyone please help me fix my bash? Thank you


$ which perl
/usr/bin/perl

$ head -1 file.pl | od -c
0000000 # ! / u s r / b i n / p e r l \n
0000020
13
  • 2
    Does the file have DOS newlines? Commented Jan 21, 2015 at 16:37
  • 2
    Did you mean to say !#/usr/bin/perl or was that a typo? The correct directive is #!/usr/bin/perl or better #!/usr/bin/env perl. Commented Jan 21, 2015 at 16:45
  • 2
    what does which perl return ? Commented Jan 21, 2015 at 16:54
  • 1
    @Karlo, egrep won't find \r\n because grep is a line oriented tool (grep will not ever find \n). Try: head -1 file.pl | od -c Commented Jan 21, 2015 at 17:03
  • 2
    strace ./perlscript.pl vs strace perl ./perlscript.pl ... to find differences Commented Jan 21, 2015 at 19:07

1 Answer 1

6

Is the filesystem where perlscript.pl is located mounted with the noexec flag?

Assuming you're on Linux, cat /proc/mounts and look for noexec on the line with the appropriate filesystem.

The noexec flag prevents anyone from calling exec on a file located on that filesystem (which is what bash does when you do ./perlscript.pl). But perl perlscript.pl calls exec on /usr/bin/perl, which then opens perlscript.pl for reading.

Files on a noexec-mounted filesystem can still have execute permission, they just can't make use of it.

Sign up to request clarification or add additional context in comments.

2 Comments

i was thinking to the very same, i tested it with a localy mounted filesystem and bingo : if as root i mount -o loop,noexec empty mounted => as my user : cd mounted ./perlscript.pl fails, . AND file is still visible with +x rights... now waiting for the confirmation from @Karlo...
Yes, thats is the problem. I moved my home directory to a mounted storage space and the 'cat /proc/mounts' has noexec next to it... thank you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.