PDA

View Full Version : Cron Job, really doing my head in, please help


lukescotty
04-20-2012, 10:04 AM
Hiya

I've been at this for days!!! maybe someone on here could put me out of my misery.

I've set up a cron job on my Cpanel to run rssposter.php every 10mins, On the server it shows its excuting the cron job correctly, but its just not posting in my forum threads.

Its doing my head in!! I just want to elimate this cronimage way and have my rssposter run every 10mins, updating all the twitter feeds

I works when I manually select run now on the rssposter, but not automatically. I've tried all these mod related to it, but there like 7 years old some of them and there not functioning correctly

Please help guys!! i wana smash something up

Regards lukescotty

kh99
04-20-2012, 10:34 AM
You can't run rssposter.php directly or it will just exit. It's meant to be run through cron.php. You could run cron.php in your cron job, but I guess it only runs one pending job and you don't know that it will be rssposter.php.

You asked about this a while back and I remember looking around a little and seeing a script that someone wrote that makes sure all the scheduled tasks run so that you can run it once from a cron job - did you find that?

lukescotty
04-20-2012, 10:43 AM
I think you sent me the link to this one https://www.vbulletin.com/forum/showthread.php/392395-Ability-to-run-Scheduled-Tasks-via-real-system-cron-VBIV-13733

"You can already do this and have been able to do it since 3.7.0 or so.

Use command line PHP and run it as a true cron job.

cd /path/to/cron.php; php /path/to/cron.php

I've posted this multiple times over the years."

but theres alot of debate on this. i've tried it, but its not being working

not understanding this run once, part of ur answer. Don't i want in to run more than once? or do you mean run once.... and its continious?

kh99
04-20-2012, 10:55 AM
I don't understand everything that's mentioned in that thread, but you could try this: Go to the scheduled task manager and find the id for the RSS poster task (edit the task and it should be at the top of the edit window). Then when setting up your cron job, make it "cron.php X" where X is the id. For instance, mine says the id is 17, so the command would be

cron.php 17

lukescotty
04-20-2012, 01:02 PM
this ID is the same too "17"

So i've created a new cron job "php /home/sheffiel/public_html/talknightlife.co.uk/cron.php 17" and it runs every 10 mins, but still no joy, do i need to remove the cronimage on the footer? are they conflicting at all (guess) ?

"php /home/sheffiel/public_html/talknightlife.co.uk/cron.php 17" this is in my command box for the cron job, btw

kh99
04-20-2012, 01:09 PM
this ID is the same too "17"

So i've created a new cron job "php /home/sheffiel/public_html/talknightlife.co.uk/cron.php 17" and it runs every 10 mins, but still no joy, do i need to remove the cronimage on the footer? are they conflicting at all (guess) ?

I don't see why they would conflict. You'd want to leave the cron image so that other tasks will run. BTW I believe you still need to set the task to run in the scheduled task manager.


"php /home/sheffiel/public_html/talknightlife.co.uk/cron.php 17" this is in my command box for the cron job, btw

Yeah, I didn't know what the exact command would look like so I was hoping you would know what I meant.

Did you check the vb logs to see if anything's getting logged when your cron job runs?

lukescotty
04-20-2012, 01:21 PM
[QUOTE=kh99;2321899]BTW I believe you still need to set the task to run in the scheduled task manager.QUOTE]

The box is checked in schedule task manager. ?? doesnt that mean its set to run ?

( aswell, even though I've set it on certain times ) when looking at the Next Time, it displays a time in the past, even though it should be operating a couple times an hour.

kh99
04-20-2012, 01:24 PM
The box is checked in schedule task manager. ?? doesnt that mean its set to run ?

Yeah, just wanted to make sure that you didn't disable it or change the times it runs thinking that it wasn't needed if you called it from your cron job.

I seen other people mention that a job doesn't seem to run even if next time is in the past, and I really don't know why that is. I'll have a look at cron.php and see if I can think of anything.

lukescotty
04-20-2012, 01:38 PM
much appreciated kh99, get back to us if u find anything which i could alter in the cron file to put this !pain in the arse! thing to rest.

kh99
04-20-2012, 01:57 PM
OK, I think that didn't work because nothing anywhere in the rest of the vb code ever sets $vbulletin->options['crontab'] to true. I don't know why, maybe it's left over from an old version or some testing. (ETA: sorry, I forgot that you'd have to look at the code for cron.php to see what I mean). Anyway, you could try this: copy cron.php to another file, like maybe runrssposter.php. Then edit that file, and replace all the code including and after the 'cron_start' hook line with:


($hook = vBulletinHook::fetch_hook('cron_start')) ? eval($hook) : false;

$cronid = intval($_SERVER['argv'][1]);
// if its a negative number or 0 set it to NULL so it just grabs the next task
if ($cronid < 1)
{
$cronid = NULL;
}

exec_cron($cronid);
$db->close();



then change your cron job to run that file. Sorry, I'd just post the entire thing but posting entire vb files isn't allowed.

lukescotty
04-21-2012, 01:04 AM
only just got in from work, gonna have to have alook at it tomorrow, thanks for the help so far!!

lukescotty
04-22-2012, 09:11 PM
kh99, yo! just tried this, but unfortunately its not working, just wondering is it possible to copy this cron file, rename it, edit a part of the code, just to run rssposter?? or is it not fesible.

or.. could i have sum setting's messed up, and it could be work?

kh99
04-22-2012, 09:17 PM
kh99, yo! just tried this, but unfortunately its not working, just wondering is it possible to copy this cron file, rename it, edit a part of the code, just to run rssposter?? or is it not fesible.

That's what I was trying to do - well, sort of. I guess it still needed a parameter. You could use this code (follow same instructions above)


($hook = vBulletinHook::fetch_hook('cron_start')) ? eval($hook) : false;

exec_cron(17);
$db->close();




Sorry, I have no way to test this so I'm just kind of guessing right now.

lukescotty
04-23-2012, 01:14 PM
Hiya, still no joy. I wonder if someone else on here could give try it out too, to see whether its me or the script.

Hmm, if i can't get it done, how could I get someone to write me a script or get futher help, even if i have to pay

regards lukescotty

kh99
04-23-2012, 02:25 PM
Yes, if someone else has an idea please jump in.

I decided just to test it without an actual cron entry. I think I've changed this enough so I can post it, so here's the entire script I used:

<?php

error_reporting(E_ALL & ~E_NOTICE);
ignore_user_abort(1);
@set_time_limit(0);

define('SKIP_SESSIONCREATE', 1);
define('NOCOOKIES', 1);
define('THIS_SCRIPT', 'cron');

$phrasegroups = array();
$globaltemplates = array();
$actiontemplates = array();
$specialtemplates = array('crondata');

require_once('./global.php');
require_once(DIR . '/includes/functions_cron.php');

($hook = vBulletinHook::fetch_hook('cron_start')) ? eval($hook) : false;

exec_cron(17);

?>



I added an rss feed, removed the cronimage from my footer to make sure it couldn't run any other way, and I ran the above script via the broswer. It worked and posted the threads from the feed. I did notice that when I used cnn as the feed it posted the news stories once, then I couldn't get it to work again even after I removed the feed from the feed manager and reenetered it. It seemed like the feed was empty for some reason. I switched to another feed and that problem went away, but I thought I'd mention it because maybe some feeds work differently and it could be part of your problem.

Thing is, this is obviously not being run as a cron job, and it's also being run through the web server as a CGI request and not via command line. So I suppose it's possible that one of those things is causing your problem. But you could test that by running the above script in a web browser.

lukescotty
04-23-2012, 04:25 PM
its becoming a bit of a headache this isnt it? I've saved the code above as a .php uploaded it to my server, created a cron job linking to that file.. but still no luck :( I've spoken to my host and they say everything is fine on the server side. I'm just thinking what I could do, i really want these feeds to auto post, otherwise i'm going to be constantly selecting "run now" every hour which i don't think i could do.

How about me giving you access to everything, on my vbulletin and my cpanel to see if you can see anything wrong?

Really appreiciate the time you've given me!

kh99
04-23-2012, 04:28 PM
Did you try just pointing your browser at it and seeing what happens?

lukescotty
04-23-2012, 06:30 PM
:: i've tried opening http://www.talknightlife.co.uk/runrssposter1.php in my browser, comes to a blank screen, am i doing this bit right

I've also wacked in more rss feeds, one from fox news, one from itv, one from sky news, to make sure its not twitter.

I must be doing something wrong here!! wheres the knife

kh99
04-23-2012, 07:34 PM
:: i've tried opening http://www.talknightlife.co.uk/runrssposter1.php in my browser, comes to a blank screen, am i doing this bit right


Yeah, it should just be blank. But you're saying you didn't see any posts. Hmm... And when you go to the scheduled task manager you have it set to run every minute and the Next time is recent (or in the past even, I think you said)?

lukescotty
04-23-2012, 07:43 PM
looking at the time you posted, all my twitter feeds updated at 21.35 which is a minute after u posted, soooo, by you clicking that php link has made it work ? do you mind clicking it again?

--------------- Added 1335213911 at 1335213911 ---------------

the cron is set to everyminute on CPanel, where as the times in VB Schedule task manager are set at different times of the hour 00, 04, 15, 31, 36, 58

kh99
04-23-2012, 07:45 PM
I'm not sure I clicked on it before I posted - I kind of think I didn't, but maybe I did.

I did just click on it now.

--------------- Added 1335214070 at 1335214070 ---------------

the cron is set to everyminute on CPanel, where as the times in VB Schedule task manager are set at different times of the hour 00, 04, 15, 31, 36, 58

OK, then it will only run at the times set in the Schedule Manager. If you want it to run every minute you'd need to set it to * - - - - -.

But it sounds like you're saying you haven't seen it run at all, and the Next RUn time is in the past?

lukescotty
04-23-2012, 07:50 PM
nah, didnt update :( i'm pulling my hair out here, dunno what the the problem could be. When ever I select the http://www.talknightlife.co.uk/runrssposter1.php it should run right ?

kh99
04-23-2012, 07:53 PM
Well, it'll only run if the vb scheduler thinks it's time for it to run.

I'll create a debug version of includes/cron/rssposter.php and get it to you so we can see what's going on.

lukescotty
04-23-2012, 08:29 PM
by the looks of it me clicking http://www.talknightlife.co.uk/runrssposter1.php could possible be working, i just need to wait 10 min for the feeds to be checked, then i'll click again.. stay put :)

kh99
04-23-2012, 08:42 PM
Oh good, I hope it's working because I'm not sure I'll be able to get to the other thing today.

So it could be that it's thecron job that's not running right. Maybe you need to add the path to the php executable or something.

lukescotty
04-23-2012, 08:42 PM
i don't know whether me refreshing the forum page is triggering it or not. Touch wood its not, so i'm going to update a twitter status every 20 mins without checking, then visit my forum, and they should line up in new threads.

--------------- Added 1335226472 at 1335226472 ---------------

ooohhh yes, i'm still at it..... I've got it to the point, where i can goto the url with my runrssposter.php and it manually works, just sorting it out with my host. Surely the problem has to got be on the hosting side? they keep changing the cron code from curl to php... wish it luck

--------------- Added 1335232526 at 1335232526 ---------------

nearly 3am but it looks to me like its all sorted

The runrssposter1.php (the last code u posted) is the one i'm using, i've wacked it in root of the server.

My host tried a cron job with , php, curl, wget but it wouldn't execute properly, then they tried this "lynx -dump http://path to php file" and it worked

Touch wood it'll keep working tomorrow

Kevin I can't thankyou enough for putting in the time and effort in getting this working, I really appreciate it. I wonder if this would be re-edited into a sticky for others, i dunno :S

Many thanks

Regards Lukescotty