Page 1 of 1

Question With Cron Jobs..

Posted: Sun Jul 25, 2004 4:00 am
by Howey
(I hope this is the right area to post =X)

But recently I coded a script for cron jobs.
It works fine when you do it manually, but when I try to make it go through cron jobs, it comes up with this error:
Could not open input file: /home/lincoln/public_html/restock.php?shop=3.
Now yes I know it uses the get function and I was wondering if that's whats screwing it up....

Im sorry I know VERY little on cron jobs :oops:

Posted: Sun Jul 25, 2004 10:01 am
by hawleyjr
I had a very similar issue. I found that passing a query string was my problem. Remove the variable off of the URL and test it.

Yes it works

Posted: Sun Jul 25, 2004 12:22 pm
by Howey
Yes without the variable it works but then my script does nothing :( is there anyway to send the variable through?

Posted: Sun Jul 25, 2004 12:25 pm
by AGISB
Most problems with Cron come form invalid permissions. Every user can have cron jobs. They are all different. So if you e.g. manually start a script as root it of course works. If you then start cron as user files might not be read due to wrong set permissions etc.

Might also have to do with path variables that a user have but cron might not.

Another problem might be that cron simply starts your program at the wrong point. Lets say you start a sript with ./sriptname.cgi and all works fine because you are in that directory. If cron starts this file it is not in that directory and variable pathing in that script might not resolve properly.
e.g in perl sripts I usally do something like this:

Code: Select all

chdir "/path-to-script-dir";

Posted: Sun Jul 25, 2004 12:29 pm
by hawleyjr
This may not be the best way to do it but is what I did was this:

What I needed:

Code: Select all

URL =http://test.com/index.php?fun=1
index.php:

Code: Select all

<?php

switch($fun){
 case: 1:
 include('/filename.php');
break;
case 2:
include('filename2.php');
break;
.
..
...
}
?>
What I did:

Code: Select all

URL =http://test.com/index_f1.php
URL =http://test.com/index_f2.php
index_f1.php:

Code: Select all

<?php
include('/filename.php');
exit;
?>
index_f2.php:

Code: Select all

<?php
include('filename2.php');
exit;
?>
This probably isn't the best way to do it but it works in my situation.

Posted: Sun Jul 25, 2004 12:33 pm
by Howey
The directory and permissions are fine its just the evil variable,
And as much as I would Like to do it your way, I cant because the whole script basically depends on that variables, it tells which items to get, where to stock the items, how many to stock, ect.

Posted: Sun Jul 25, 2004 12:35 pm
by hawleyjr
Is it possible to put the variables in a table and when your cron job runs pull the necessary variables from the db?

Posted: Sun Jul 25, 2004 12:42 pm
by Howey
hmmm....well I was thinking sense this is all time related would it work just as well, if I had it time oriented?
so it like

Code: Select all

$minutes = date(i);
$true = $minutes/15;

if($true == '1' || $true == '2') &#123;
include('blah.php?shop=2');
&#125;
Would that work you think?

Posted: Sun Jul 25, 2004 12:44 pm
by hawleyjr
its worth a try. I don't believe you can pass variables via include() but you can do the following:

Code: Select all

<?php
$user_name = 'james';

include('my_file.php');
?>
my_file.php:

Code: Select all

<?php
echo $user_name;
?>
Let us know how it works for you.

Posted: Sun Jul 25, 2004 12:48 pm
by Howey
Alright will do =D thanks for all your help though :D