Cron Troubles

I’m attempting to run a crontab, but I get an error from crontab every hour claiming permission has been denied for the lock and the script does not run. This is how I phrased it:


I tried adding the hidden directory the username actually lies in, adding a semicolon, etc., but I can’t find what’s wrong. Any ideas?

Oh, and the email is as follows:

From: Cron Daemon

Subject: Cron username@server /usr/local/bin/setlock -n /tmp/cronlock.1581374.13951 sh -c $’/usr/local/php5/bin/php \012/home/username/domain/scripts/script.php’

sh: line 2: /home/username/domain/scripts/script.php: Permission denied

Edited for privacy of course.

It looks to me that you have a linefeed in your crontab entry, just like it is in the post. It’s supposed to be on the same line. The output even shows the /012, which is a linefeed.

First, get rid of the linefeed and see if that helps. While you’re waiting, go to the command line and type: crontab -l (that’s a small L)
Then cut and paste the command portion back into the command line and see if it works.


maybe you need to give to your script.php a chmod u+x script.php

use VIC3M to get some discount on all plans +10% on storage and bandwith.

I tried changing it to /dh/cgi-system/php5.cgi instead of /usr/local/php5/bin/php and got this added to the email response:

X-Powered-By: PHP/5.2.3
Content-type: text/html

I’m removing the linefeed and leaving the new location. We’ll see what happens.

crontab -l returns this:

@hourly /usr/local/bin/setlock -n /tmp/cronlock.1581374.13951 sh -c $’/dh/cgi-system/php5.cgi \012/home/username/domain/scripts/script.php’

Feeling dumb here. I apparently had it set as 644, not 744. Fixed it, will respond back when it gives me my next update.

.php scripts don’t have to be executable; just readable. Only the ‘php’ binary needs to be x, which it is.

Did you create the cronjob in the panel? The setlock portion of the command seems odd. Maybe it’ll work. Looking at the crontab -l, it still shows the \012 part. The mail response shows that php ran, but perhaps the rest got ignored due to the linefeed.

If I created that cronjob via the ‘crontab -e’ command, mine would have looked like:
0 * * * * /dh/cgi-system/php5.cgi /home/username/domain/scripts/script.php


It was created through the panel. Admittedly due to laziness.

FIXED! It works now. Thanks everyone.
It was that it needed to be executable. Why, don’t ask me. Nevertheless, that ended up being the problem.

I don’t understand why people use the interpreter with a shebang like that.

my crontab executes php the way php is meant to be executed (on DH at least)…

AskApache Web Development Blog