Re: Corn job anomaly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


I suspect you are taking the pipe or semicolon literally.

Drop the pipe and semicolon entirely. This should work:

    /usr/bin/php5 -c /home/123456/etc/php.ini -f /home/123456/data/auto_reminder.php

The "pipe" (|) in unix (and I assume this is unix) means to pipe the output
of php5 -c config to the command "-f /home...php". Which (-f) isn't a command.

The "semicolon" (;) in unix means "do this command first; then do this command"
so in your second part it is running /home/123456/data/auto_reminder.php -udb123456 after it runs php5.

Usually php5 -c php.ini will run PHP in interactive mode, and sits and
waits for input. When run from cron, there is no input, so it dies, unable
to pipe the output (there is none) or just run the next command.

So -- lose the pipe, lose the semicolon, just run the command above in cron
(and on the command line) and it should "just work."


On Tue, 20 Sep 2016, Karl DeSaulniers wrote:

Hi Richard & Bert,
Thanks for the responses. I think I understand what you are both saying.

Not sure where my database is housed as I am using a hosting provider (Mediatemple)
and they allow limited access to such things or I am unaware how to access them.

For my current issue, lets just say my username is  db123456
db123456 is the root user who has access to all databases
However I am not sure if the cron job runs under this user.

This is the command line I have currently that is not working

/usr/bin/php5 -c /home/123456/etc/php.ini | -f /home/123456/data/auto_reminder.php

My hosting company says I can force my php.ini with -c <path>|<file>
but this errors out saying -f command can not be found.

I tried this:

/usr/bin/php5 -c /home/123456/etc/php.ini | /home/123456/data/auto_reminder.php

but then I get the same error I originally had saying php doesn't exist.
I tried a semicolon like I had seen on some message boards and the double &&
but still no dice.

I even tried to set the user in the args like so

/usr/bin/php5 -c /home/123456/etc/php.ini ; /home/123456/data/auto_reminder.php -udb123456

again, no dice.

I think it may be that the cron is under another user and that my original CL works, just not sure how to find out.
I would call my hosting provider to ask, but I always get the same response ...

We don't troubleshoot peoples code it is out of our scope of support.


Karl DeSaulniers
Design Drumm

On Sep 20, 2016, at 1:07 PM, Richard <inbound-lists-php@xxxxxxxxxxxxxxxxxxxxx> wrote:

------------ Original Message ------------
Date: Tuesday, September 20, 2016 12:54:38 -0500
From: Karl DeSaulniers <karl@xxxxxxxxxxxxxxx>

On Sep 20, 2016, at 7:21 AM, Richard
<inbound-lists-php@xxxxxxxxxxxxxxxxxxxxx> wrote:

Date: Tuesday, September 20, 2016 03:26:39 -0500
From: Karl DeSaulniers <karl@xxxxxxxxxxxxxxx>

On Sep 20, 2016, at 3:22 AM, Lester Caine <lester@xxxxxxxxxxx>

On 20/09/16 09:14, Karl DeSaulniers wrote:
Pardon my ignorance, but what do you mean full path?
Full path to php application.
Cron jobs run as 'root' and so need and user account settings
added manually if they do not match the 'root' environment.

OH, ok, I did read something about root earlier.
I think it was something like:

root /usr/bin/php5 /home/(directory name

But not positive. I will have to research that more.
Thank you.

Whether cron jobs run as root or a standard user depends on how
they are set up. If set up under a user -- which is the better
approach for general use -- they will run as that user. Really only
system-type cron jobs (that require root access) should be set up
to run as root.

If you use the command:

 crontab -e

from a user account, then the crontab is set up as that user. The
first 5 fields/values are time/date related, followed by the
command to be invoked. See: man -s5 crontab  for more details.

In that case, the user that mysql sees is the user that is running
the job. So, if your mysql authentication is set to accept
connections/give access to say the user your web server is running
as (which is how php will show by default), then you will either
need to pass those credentials in your cron job php script or,
give the user that's running the cron job access.

Again, thank you for the response Richard.

Would you possibly have a link to how to set that up? I mean the
actual commands. My trouble is I don't know what commands and how
to write them. Like including a user, forcing the PHP.ini and
executing the script. All in one line. That is what I am trying to
accomplish and not sure how. Need to read up on the proper way to
do this.

The php.ini that is used will be based on the php rules for the
path(s) (and order) it searches for that file.

The user that is running the script will be the user that the cron
job is set up under. If you set up a cron job as a standard user you
can't assign it to run as a different user. If the issue is mysql
access, you do that just the way you would in a [web]server parsed
php file.

The script is whatever you put on the crontab line.

The script you reference from the crontab entry can be a shell script
that does some setup, and then calls your php script.  Your php
script can have include files (e.g., for mysql connection setup) just
as you might have in a [web]server parsed php file.

PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Peter Beckman                                                  Internet Guy

PHP Database Mailing List (
To unsubscribe, visit:

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux