cron jobs using curl

jmsconsult02

Verified User
Joined
Jan 20, 2008
Messages
8
I have several jobs that use curl to run from several different domains using the same account.

I.e.
I have a user account called user1. user1 has 3 domains www.domain1.com, www.domain2.com and www.domain3.com.

In domain1.com i have a curl job (curl http://www.domain1.com/dosomething.php)

In domain2.com i have a curl job (curl http://www.domain2.com/dosomething.php)

Neither of those 2 jobs will run. I do the same exact curl comman in an account that has a single domain and it works. When I run the curl job from a browser it works.

I have the same problem running something like php /home/user1/domains/domain1.com/public_html/dosomething.php

I've tried manually putting the command into the root crontab and that doesn't work either.

In the cron logs it shows that it ran but it hasn't..

I've seen similar posts but no solutions.

Thank you for your help.

Jon
 
Hi,
Please can you post the cron job line in question and also post the output of the command you are trying to run when ran in the shell. Do you mean to say that the curl/php commands you are trying work from the shell but not when you put them into a cron?
 
Hi,
Please can you post the cron job line in question and also post the output of the command you are trying to run when ran in the shell. Do you mean to say that the curl/php commands you are trying work from the shell but not when you put them into a cron?
I can only tell if it works by data getting inserted into a table. The cron job entry is...

55 23 * * * curl http://somedomain.com/cron_orders.php

I need to keep the domain in question anonymous but in general when i run http://somedomain.com/cron_orders.php from a browser it inserts a record into a table. As you see i have it running at 11:53 pm everyday..

I have this same process working properly on another user account and domain
 
So just to confirm does this command work from the shell? What is the output of

Code:
curl http://somedomain.com/cron_orders.php

If this command works as you had hoped when ran as a normal user not root then there is no reason it shouldn't work inside a standard cron. Also have you tried specifying an exact path to the file instead which would make more sense if it's on the local server?

Code:
curl /usr/home/someuser/domains/somedomain.com/cron_orders.php
 
So just to confirm does this command work from the shell? What is the output of

Code:
curl http://somedomain.com/cron_orders.php

If this command works as you had hoped when ran as a normal user not root then there is no reason it shouldn't work inside a standard cron. Also have you tried specifying an exact path to the file instead which would make more sense if it's on the local server?

Code:
curl /usr/home/someuser/domains/somedomain.com/cron_orders.php
curl http://somedomain.com/cron_orders.php will update a table where i can see if it ran or not. it will have a date stamp. When i run http://www.somedomain.com/cron_orders.php from a browser and then query the table i can see the new entries.

I have other cron jobs running in this account and other accounts that work fine. but this job (cron_orders.php) also is used in other domains..same code, different domain but all output entries into a mysql table. This should work...


i've tried this as well...

/usr/local/bin/php /home/someuser/domains/somedomain.com/public_html/cron_orders.php

but that didn't work.

i don't think this would work..

curl /usr/home/someuser/domains/somedomain.com/cron_orders.php since it needs to run php. Doesn't curl need to run a url?
 
Last edited:
You may need to use
Code:
php [B]-f[/B] /home/someuser/domains/somedomain.com/public_html/cron_orders.php[CODE]

You are right about curl needing to be given a URL rather than a local file.
 
You may need to use
Code:
php [B]-f[/B] /home/someuser/domains/somedomain.com/public_html/cron_orders.php[CODE]

You are right about curl needing to be given a URL rather than a local file.[/QUOTE]
heres the output from curl http://www.somedomain.com/affiliate/cron_add_test.php (replaced somedomain.com with the correct domain)

curl.. somedomain.com/affiliate/cron_add_test.php does exist on the server ..  I created this test that simply adds a record to a table... when i run it from a browser it works..when i run using php it works, but does not get the ip address that i would like to insert into the table..

php code..
<?php
if(!$con)
{
include "../system/connection.php";
$con=new connection();
}
	$ip = $_SERVER['REMOTE_ADDR'];
	$website_id = getLocalWebsiteId(); // defined in include code
	$created = date("Y-m-d H:i:s");
	$flds['created'] = $created;
	$flds['ip'] = $ip;
	$flds['website_id'] = $website_id;	
	$sql = build_insert_query($flds,"user_log");  // create insert into table code...
	$res = mysql_query($sql);  // runs query...



curl output

== Info: About to connect() to www.somedomain.com port 80 (#0)
== Info:   Trying 69.49.62.33... == Info: connected
== Info: Connected to www.somedomain.com (69.49.62.33) port 80 (#0)
=> Send header, 191 bytes (0xbf)
0000: GET /affiliate/cron_add_test.php HTTP/1.1
002b: User-Agent: curl/7.17.1 (i686-pc-linux-gnu) libcurl/7.17.1 OpenS
006b: SL/0.9.7a zlib/1.2.1.2 libidn/0.5.6
0090: Host: www.somedomain.com
00b0: Accept: */*
00bd:
<= Recv header, 24 bytes (0x18)
0000: HTTP/1.1 404 Not Found
<= Recv header, 37 bytes (0x25)
0000: Date: Wed, 01 Oct 2008 19:03:16 GMT
<= Recv header, 18 bytes (0x12)
0000: Server: Apache/2
<= Recv header, 22 bytes (0x16)
0000: Accept-Ranges: bytes
<= Recv header, 34 bytes (0x22)
0000: Vary: Accept-Encoding,User-Agent
<= Recv header, 28 bytes (0x1c)
0000: Transfer-Encoding: chunked
<= Recv header, 25 bytes (0x19)
0000: Content-Type: text/html
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 531 bytes (0x213)
0000: 90
0004: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">.<HTML><HEAD>.
0044: <TITLE>404 Not Found</TITLE>.</HEAD><BODY>.<H1>Not Found</H1>.Th
0084: e requested URL
0096: 43
009a: /affiliate/cron_add_test.php was not found on this server..<HR>.
00da: <I>
00df: 128
00e4: www.somedomain.com</I>.</BODY></HTML>.....................
0124: ................................................................
0164: ................................................................
01a4: ................................................................
01e4: ........................................
020e: 0


I have no clue as to why this doesn't work..it should..


One last thing..i have a cronjob called email_queue.php that sends out email ...works great ..
entry in cron is curl http://www.somedomain.com/system/email_queue.php

I copied email_queue.php to email_que.php and i get the same 404 not found error when using curl.

I've tried creating simple tests but curl always comes up with not found. 

Any clues?

btw, i do the same using plesk and have never had a problem with it..
 
Last edited:
Back
Top