Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 31st, 2011, 08:48 AM
HDRebel2112 HDRebel2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 56 HDRebel2112 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old May 31st, 2011, 09:11 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 41 m
Reputation Power: 1485
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

Reply With Quote
  #3  
Old May 31st, 2011, 04:43 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,237 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 50 m 19 sec
Reputation Power: 4445
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

Reply With Quote
  #4  
Old May 31st, 2011, 04:55 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,698 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 54 m 57 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
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

Reply With Quote
  #5  
Old May 31st, 2011, 05:25 PM
HDRebel2112 HDRebel2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 56 HDRebel2112 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Cron Job

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap