Solved

PEAR Mail Won't Work in Crontab'd PHP Script

Posted on 2009-03-30
17
521 Views
Last Modified: 2013-12-23
I have a PHP script that works perfectly when requested from the server; however, when I command it to be ran via Crontab like so:
lynx -dump http://www.emarketbuilders.com/admin/send_campaign_cron.php

I get the following error sent to me via email:
                                   Not Found

   The requested document was not found on this server.
     _________________________________________________________________


    Web Server at emarketbuilders.com
0
Comment
Question by:EMB01
  • 9
  • 8
17 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24023078
Hi,
remeber that there is no PATH when running from crontab (besides /bin and /usr/bin).
You need to provide full paths not only in the crontab itself but also in the script.

wmp

0
 
LVL 14

Author Comment

by:EMB01
ID: 24023106
How should my Cron command work, then? My script currently does use the full path.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24023429
So check additional environment settings (variables)
Problems with cron are in almost every case related to some environmentals being uninitialized.
0
 
LVL 14

Author Comment

by:EMB01
ID: 24023496
I'm sorry I'm not very experienced with Crontab. Could you be more specific as to what variables you would like me to check and/ or how to check them? Thank you.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 24023687
While in the environment where the script works fine, issue 'printenv' and examine the settings found.
 Some important values? Assume that they are not there when the script is run by cron.
 
 It could help to let the script be run out of root's crontab, and prepending a 'su - [user]' so that the line reads

su - [user] -c "lynx -dump http://www.emarketbuilders.com/admin/send_campaign_cron.php"

where [user] is the one who normally runs the script (don't type the brackets [  ] )
 
 Sorry that I can't be more specific. I just don't know your environment, nor do I know what your script actually does.
0
 
LVL 14

Author Comment

by:EMB01
ID: 24023963
Okay, it's working, now! I had a wrong file name and include path for PEAR; so when I fixed those and used Lynx it worked. One question: Is there any benefit to using Lynx or should I use something better (what's the fastest, best way to run the script)?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24024158
The only thing that comes to my mind right now is WebCon (w3c) -

http://www.w3.org/ComLine/

Don't know if it can do what you want it to, nor if it's faster/better than lynx.

HTH anyway,

wmp

0
 
LVL 14

Author Comment

by:EMB01
ID: 24024186
Would it be faster to just run it from the command line like /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaign_cron.php?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24024265
If you have the php CLI installed, try

php  /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaign_cron.php

If not, you will need your web server to run that script.

php CLI should be a bit faster than lynx + apache.
0
 
LVL 14

Author Comment

by:EMB01
ID: 24024322
Hey, I can open a new question if need be; but when I run it in PHP I get a bunch of errors. Do I need to change permissions or run the command with some flags?
PHP Warning:  require_once(): SAFE MODE Restriction in effect.  The script whose uid is 10001 is not allowed to access /usr/share/pear/Mail.php owned by uid 0 in /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaigns_cron.php on line 11
PHP Warning:  require_once(/usr/share/pear/Mail.php): failed to open stream: Success in /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaigns_cron.php on line 11
PHP Fatal error:  require_once(): Failed opening required '/usr/share/pear/Mail.php' (include_path='.:') in /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaigns_cron.php on line 11
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24026963
Take care that the user with ID 10001 has access to  /usr/share/pear/Mail.php.
Check group ownership with 'ls -l /usr/share/pear/Mail.php' and put the user (10001) in the same group that script belongs to -
'usermod -a -G [group] [user]
Additionally make /usr/share/pear/Mail.php group-accessible (if it isn't already) by issuing 'chmod g+rx /usr/share/pear/Mail.php '
 
0
 
LVL 14

Author Comment

by:EMB01
ID: 24028555
Here's the output:
-rw-r--r-- 1 root root 8934 Feb  7 12:00 /usr/share/pear/Mail.php

I'm not 100% sure what the [group] variable is from:
usermod -a -G [group] [user]

Can I skip that part and simply make it group-accessible with:
chmod g+rx /usr/share/pear/Mail.php

Is using PHP that much faster, or will is the difference between PHP and Lynx even noticeable?

Thanks for your continued help.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24028834
OK, just read from your post that it is PHP SAFE MODE.
This means that php scripts are only allowed to access files belonging to the same owner/group as the script itself.
I don't know if it's possible for you to change owner/group of /usr/share/pear/Mail.php to be the same as the ones of /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaign_cron.php, but this would be a solution.
You can also switch off SAFE MODE (beginning with PHP 6 it's gone anyway.
As for speed - php CLI should be only a bit faster, but I guess one can't tell exactly without testing.
wmp
 


 
0
 
LVL 14

Author Comment

by:EMB01
ID: 24028920
According to my Plesk control panel, safe mode is off... I think I'll just use Lynx for, now and work the PHP thing out later as execution time becomes a larger issue.

Regarding the Lynx method, I keep getting emails everytime the script is run like "Cron <emarketbuilders@emarketbuilders> lynx -dump http://www.emarketbuilders.com/admin/send_campaigns_cron.php" and there won't be anything in the message. Can I shut these off by changing my current command which is "lynx -dump http://www.emarketbuilders.com/admin/send_campaigns_cron.php"

Note: When I clear the -dump flag, it says "Your Terminal type is unknown! ..."
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 24029202
Simply change your crontab entry to read
. . . . .  lynx -dump http://www.emarketbuilders.com/admin/send_campaign_cron.php >/dev/null 2>&1
That should do the trick.
safe mode might be off for your web server's php, but it might be enabled for your php CLI binary.

 
0
 
LVL 14

Author Comment

by:EMB01
ID: 24029931
Thanks, again for your outstanding support.
0
 
LVL 14

Author Closing Comment

by:EMB01
ID: 31564518
Sorry it took so long to accept. I didn't realize this question was still open, somehow... Best wishes!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Lets look at the default installation and configuration of FreeProxy 4.10 REQUIREMENTS 1. FreeProxy 4.10 Application - Can be downloaded here (http://www.handcraftedsoftware.org/index.php?page=download) 2. Ensure that you disable the windows fi…
Some time ago I was asked to set up a web portal PC to put at our entrance. When customers arrive, they could see a webpage 'promoting' our company. So I tried to set up a windows 7 PC as a kiosk PC.......... I will spare you all the annoyances I…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now