1753960 Members
7551 Online
108811 Solutions
New Discussion юеВ

Cron permission problem

 
Kepstein
Occasional Advisor

Cron permission problem

Hi All,

I have a strange cron permission problem. I have a small perl script that needs to run every day at 16:00. The scheduling side of this is no problem. The problem I have is that when cron executes my perl script I get the following error:

sh: in: Execute permission denied.

I've checked the file permission - no problems there. I've also checked that the path to perl in the header of my perl script points to my valid perl path.

I've also checked that the script runs as root without problem from the command line, and there are no problems there either.

I'm a little stumped.

Anyone got some ideas. TIA

Kevin
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: Cron permission problem

Since it runs from an interactive shell, this has to be an environment problem. I would actually run the Perl script from within a wrapper shell script that is in turn started by cron. This will make it easier to set and export any needed environment variables and pass any needed arguments to the Perl script without having to worry about any cron syntax. Remember cron's environment is intentionally very sparse and ${PATH} is extremely limited. The user's .profile is not sourced by cron.


Because of your error message, it appears to me that the shell (which cron uses) rather than Perl is having the problem and the most likely culprit is a small error in your "shebang line"
Is the first line of your Perl script very similar to this?
#!/usr/bin/perl -w

The only other "gotcha" is that stdin is no longer a terminal (tty) device so that too could have some impact depending upon what your script actually does. Notice that it cannot execute the "in" command.
If it ain't broke, I can fix that.
Kepstein
Occasional Advisor

Re: Cron permission problem

Hi,

I had throught that it might be an issue with STDIN / STDOUT but my script simply picks up a file and makes an FTP connection and drops it off the file. That's about it from a functionality point of view for the script. I also looked for the substring "in" in my perl script, and the only place that it exists is in the first line of the script

#!/usr/local/bin/perl

with "in" being a substring of "bin"

What does the -w switch do?

Thanks.
Kevin
A. Clay Stephenson
Acclaimed Contributor

Re: Cron permission problem

Do a man perlrun. It will explain the -w flag but essentially it enables warnings. You should also add "use strict;" Those two things will make your Perl much more robust although you will need to get used to declaring variables as:
my $a;
or
our $b;
... but that's a good thing.

Since you are FTP'ing, I assume that you are using Net::FTP. If not, you may be having an input/output rediection problem.

Start by creating your wrapper script and exporting any variables that you might think you need. If there are any commands that you are using that are not in /usr/bin then make sure that you augment PATH or use absolute pathnames.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Cron permission problem

Oh, and one other gotcha might be that you have to add some -I arguments to your Perl invocation in case under cron it doesn't know where to look for modules.
If it ain't broke, I can fix that.
Kepstein
Occasional Advisor

Re: Cron permission problem

Hi,

I tried with a wrapper script. Inside the script I included the .profile for the user. Then I noticed something interesting. I had a mistake in my filename when changing it to the wrapper script, so nothing should have run, yet I got exactly the same error! No I believe that the problem has nothing to do with my perl script at all but something odd happening within the cron sub system. Something I have a question about - does cron have problems running programs if the user that cron is running as has a profile of /bin/false?

Thanks
Kevin
Kepstein
Occasional Advisor

Re: Cron permission problem

Hi,

I found the problem - and it's a strange error for a simple config problem.

The problem was inmy scheduling. I had 1 too many "*" in my scheduling. I removed the extra and all is well now!

Such a mis-leading error, and what a wild goose -chase.

Thanks for the responses though.

Kevin.
Kepstein
Occasional Advisor

Re: Cron permission problem

Cron does not check your crontab entries and will save your crontab even if theres a mistake. The problem I had was 1 too many "*" characters in the scheduling. After fixing this, cron ran my script as expected.