The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Operating Systems
> Linux Help
|
Cron Job
Discuss Cron Job in the Linux Help forum on Dev Shed. Cron Job Linux Help forum discussing topics including usage, troubleshooting, modules, and distributions. Linux is an open source OS, based on UNIX.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 31st, 2011, 08:48 AM
|
|
Contributing User
|
|
Join Date: May 2011
Posts: 56
Time spent in forums: 1 Day 29 m 5 sec
Reputation Power: 3
|
|
|
Cron Job
I have this script:
Code:
<?php
if($_GET['key']=="a"){
#!/usr/local/bin/php -q
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name3 WHERE review_show='n'";
$result=mysql_query($sql);
$num_results=mysql_num_rows($result);
if($num_results > 0){
if($num_results==1){
$message="You have ".$num_results." review unapproved.";
}
else{
$message="You have ".$num_results." reviews unapproved.";
}
mail('webmaster@ghosthuntersportal.com','GHP Reviews', $message, 'From: sales@ghosthuntersportal.com');
}
$sql2="SELECT * FROM $tbl_name4 WHERE rma_issued='n'";
$result2=mysql_query($sql2);
$num_results2=mysql_num_rows($result2);
if($num_results2 > 0){
if($num_results2==1){
$message="You have ".$num_results2." RMA Number Requested.";
}
else{
$message="You have ".$num_results2." RMA Numbers Requested.";
}
mail('webmaster@ghosthuntersportal.com','GHP RMA Number Requests', $message, 'From: sales@ghosthuntersportal.com');
}
echo "Emails Sent.";
}
?>
with a Cron Job Command of /usr/bin/php -f /home/zyquo/public_html/ghosthuntersportal.com/cj_run.php?key=a
It's set to execute once every minute... and I get nothing at all.
|

May 31st, 2011, 09:11 AM
|
|
|
|
I've never run php as a 'script', either directly or via cron but ... I do know the shebang line (the #!/usr/bin/php) HAS to be the first line of the script if you are wishing the shell to interpret it as php. What does yor line in cron that invokes this look like?
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|

May 31st, 2011, 04:43 PM
|
|
|
|
Also I don't believe you can pass '..?a=whatever' get arguments or use $_GET from a cli php script. GET is populated from data provided by a web server, and you're not using a web server from cli scripts.
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
|

May 31st, 2011, 04:55 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Quote: | Originally Posted by SimonJM I've never run php as a 'script', either directly or via cron but ... I do know the shebang line (the #!/usr/bin/php) HAS to be the first line of the script if you are wishing the shell to interpret it as php. |
Right. Since the cron command invokes /usr/bin/php the # will be interpreted as a comment and ignored.
Quote: | Originally Posted by Doug G Also I don't believe you can pass '..?a=whatever' get arguments or use $_GET from a cli php script. GET is populated from data provided by a web server, and you're not using a web server from cli scripts. |
Also right. I don't know how cron runs commands but that ? might even be interpreted as a metacharacter (by cron, by the shell, by somebody). If not then the system is looking for a file named "cj_run.php?key=a" (which doesn't exist).
PHP would have dumped a message to stderr (which isn't captured in cron logs IIRC) and quit, thus no output.
On that note, CLI scripts can use $argv:
PHP Code:
if (!empty($_GET["key"])) $key = $_GET["key"];
else if (!empty($argv[1])) $key = $argv[1];
Code:
/usr/bin/php -f /path/cj_run.php a
|

May 31st, 2011, 05:25 PM
|
|
Contributing User
|
|
Join Date: May 2011
Posts: 56
Time spent in forums: 1 Day 29 m 5 sec
Reputation Power: 3
|
|
|
Got this working... removed the key=a and placed it outside the public_html folder so it be accessed by a web browser.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|