473,395 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

a PHP script works fine when called from the browser but not as a shell script

I've got a script called makeRss.php. It works fine if I try to open it
with my browser. It makes an RSS feed for every page on my site. You
can see it working here:

http://www.autostratus.com/index.php?whatPage=makeRss

It does just what I want it to do.

However, I need for this script to get called every 15 minutes. So I
set it up as a cron job. And cron doesn't like calling this thing. Cron
is nice enough to send me an email with an error message. Every 15
minutes I get this:

/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 1: ?php:
No such file
or directory
/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 2: syntax
error near
unexpected token `"tagIndexLibrary.php"'
/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 2:
`include_once("tagIndexLibrary.php");
Why would cron have a problem if the script works fine from the web
browser?

Dec 21 '05 #1
10 2133
On 21 Dec 2005 09:06:53 -0800, "lawrence k" <lk******@geocities.com> wrote:
I've got a script called makeRss.php. It works fine if I try to open it
with my browser. It makes an RSS feed for every page on my site. You
can see it working here:

http://www.autostratus.com/index.php?whatPage=makeRss

It does just what I want it to do.

However, I need for this script to get called every 15 minutes. So I
set it up as a cron job. And cron doesn't like calling this thing. Cron
is nice enough to send me an email with an error message. Every 15
minutes I get this:

/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 1: ?php:
No such fil


You seem to be trying to run the .php file directly. This won't work; you
either need a #! line at the beginning, or you need to run it via PHP.

So either:

#!/path/to/php

as the first line, which will mess things up when it's run via the web, or
change your cron entry to:

*/15 * * * * /path/to/php /path/to/makeRss.php

... as I'm assuming it's currently something like:

*/15 * * * * /path/to/makeRss.php

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 21 '05 #2
In our last episode,
<11*********************@g49g2000cwa.googlegroups. com>,
the lovely and talented lawrence k
broadcast on comp.lang.php:
/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 1: ?php:
No such file
or directory
/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 2: syntax
error near
unexpected token `"tagIndexLibrary.php"'
/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 2:
`include_once("tagIndexLibrary.php");
Why would cron have a problem if the script works fine from the web
browser?


The executable is php, not your php script. The server knows
this. The operating system does not.

The first two characters of your file need to be #! followed
immediately by the path to php (not makeRss.php) - and when I
say first two characters, I mean the first two characters with
no preceding empty lines or spaces. Or you can call php from
chron with your script as an argument.

--
Lars Eighner us****@larseighner.com http://www.larseighner.com/
My mail reader can beat up your mail reader.
Dec 21 '05 #3

Andy Hassall wrote:
On 21 Dec 2005 09:06:53 -0800, "lawrence k" <lk******@geocities.com> wrote:

However, I need for this script to get called every 15 minutes. So I
set it up as a cron job. And cron doesn't like calling this thing. Cron
is nice enough to send me an email with an error message. Every 15
minutes I get this:

/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 1: ?php:
No such fil


You seem to be trying to run the .php file directly. This won't work; you
either need a #! line at the beginning, or you need to run it via PHP.

So either:

#!/path/to/php

as the first line, which will mess things up when it's run via the web, or


I ran phpinfo() to find out the path, and this is the info I got:

PATH /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin

_SERVER["PATH"] /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin

_SERVER["PATH_TRANSLATED"] /home/httpd/vhosts/autostratus.com/httpdocs/info.php

_ENV["PATH"] /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin
I'm sorry I know so little about shell scripts, but I can't figure from
this what the address in the first line should be. Is it like this:

#!/sbin/php

Dec 21 '05 #4
On 21 Dec 2005 15:32:30 -0800, "lawrence k" <lk******@geocities.com> wrote:
Andy Hassall wrote:
On 21 Dec 2005 09:06:53 -0800, "lawrence k" <lk******@geocities.com> wrote:
>However, I need for this script to get called every 15 minutes. So I
>set it up as a cron job. And cron doesn't like calling this thing. Cron
>is nice enough to send me an email with an error message. Every 15
>minutes I get this:
>
>/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 1: ?php:
>No such fil


You seem to be trying to run the .php file directly. This won't work; you
either need a #! line at the beginning, or you need to run it via PHP.

So either:

#!/path/to/php

as the first line, which will mess things up when it's run via the web, or


I ran phpinfo() to find out the path, and this is the info I got:

PATH /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin

_SERVER["PATH"] /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin

_SERVER["PATH_TRANSLATED"] /home/httpd/vhosts/autostratus.com/httpdocs/info.php

_ENV["PATH"] /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin

I'm sorry I know so little about shell scripts, but I can't figure from
this what the address in the first line should be. Is it like this:

#!/sbin/php


Type the following at a shell prompt:

which php

This will tell you the path.

Failing that, use phpinfo(), and look for "--prefix=" in the configure line.
If it's "--configure=/usr", then the CLI version of PHP is at /usr/bin/php.

And you probably don't want to be adding the #! line due to the warnings I
wrote immediately after it. You probably want the second option, changing your
cron entry to call php with the script as an argument.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 22 '05 #5
On Wed, 21 Dec 2005 09:06:53 -0800, lawrence k wrote:
Why would cron have a problem if the script works fine from the web
browser?


Because you didn't specify the interpreter at the beginning of the script.
#!/usr/bin/php would be an excellent choice first line of the script,
if your php executable resides in /usr/bin.

--
http://www.mgogala.com

Dec 22 '05 #6
On Wed, 21 Dec 2005 17:42:34 +0000, Andy Hassall wrote:
*/15 * * * * /path/to/php /path/to/makeRss.php


This is disgusting! Andy, I'm disappointed.

--
http://www.mgogala.com

Dec 22 '05 #7
On Thu, 22 Dec 2005 00:51:16 GMT, Mladen Gogala <go****@sbcglobal.net> wrote:
On Wed, 21 Dec 2005 17:42:34 +0000, Andy Hassall wrote:
*/15 * * * * /path/to/php /path/to/makeRss.php


This is disgusting! Andy, I'm disappointed.


In what way?

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 22 '05 #8
In our last episode,
<11**********************@g49g2000cwa.googlegroups .com>, the
lovely and talented lawrence k broadcast on comp.lang.php:

Andy Hassall wrote:
On 21 Dec 2005 09:06:53 -0800, "lawrence k" <lk******@geocities.com> wrote:
>
>However, I need for this script to get called every 15 minutes. So I
>set it up as a cron job. And cron doesn't like calling this thing. Cron
>is nice enough to send me an email with an error message. Every 15
>minutes I get this:
>
>/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 1: ?php:
>No such fil
You seem to be trying to run the .php file directly. This won't work; you
either need a #! line at the beginning, or you need to run it via PHP.

So either:

#!/path/to/php

as the first line, which will mess things up when it's run via the web, or

I ran phpinfo() to find out the path, and this is the info I got: PATH /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin _SERVER["PATH"] /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin _SERVER["PATH_TRANSLATED"] /home/httpd/vhosts/autostratus.com/httpdocs/info.php _ENV["PATH"] /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin
I'm sorry I know so little about shell scripts, but I can't figure from
this what the address in the first line should be. Is it like this: #!/sbin/php


run
which php

That returns (in FreeBSD, will almost certainly vary in other
unices):

/usr/local/bin/php

That's what goes in the she-bang line:
#!/usr/local/bin/php

("She-bang" is an informal expression for #!).

This works for many kinds of scripts etc. in other languages,
such as perl, various shells, etc.

However, others have pointed out, php is not entirely unbroken
in this regard, and it would be more convenient for you if you
only had one version of each script, so the better option for
you is to run php from chron with your script as an argument.

--
Lars Eighner us****@larseighner.com http://www.larseighner.com/
Good Morning, Carnivore! - Anthrax botulin nuclear flight mail Akbar reservoir
Ramadan letter activate bridge Abdul safehouse virgins money detonators Allah
smallpox Glaspie Springfield agent airport dispersal facility counterfeit
Dec 22 '05 #9
On Thu, 22 Dec 2005 01:01:57 +0000, Andy Hassall wrote:
This is disgusting! Andy, I'm disappointed.


In what way?


Andy, the proper way to do it is #!/path/to/php in the first line
Calling PHP explicitly doesn't conform the IGO (International Geeks
Organization) standard for aesthetics. As a geek, I must protest.
Merry Christmas and a happy New Year!

--
http://www.mgogala.com

Dec 22 '05 #10

Andy Hassall wrote:
On 21 Dec 2005 09:06:53 -0800, "lawrence k" <lk******@geocities.com> wrote:
However, I need for this script to get called every 15 minutes. So I
set it up as a cron job. And cron doesn't like calling this thing. Cron
is nice enough to send me an email with an error message. Every 15
minutes I get this:

/home/httpd/vhosts/autostratus.com/httpdocs/makeRss.php: line 1: ?php:
No such fil


You seem to be trying to run the .php file directly. This won't work; you
either need a #! line at the beginning, or you need to run it via PHP.

So either:

#!/path/to/php

as the first line, which will mess things up when it's run via the web, or
change your cron entry to:

*/15 * * * * /path/to/php /path/to/makeRss.php

... as I'm assuming it's currently something like:

*/15 * * * * /path/to/makeRss.php


Thanks so much for all your help. I took the second route you here
suggest. And I got it to work, for the most part. The RSS feeds are
being created. However, the script is not allowed to run chmod() when
it is called by cron, though it has no problem running chmod() when it
is called from the browser. Why would that be? Is the user different?
Is the user Apache when it is called from the browser, and PHP when
called as a shell script? If so, I assume PHP lacks the rights to
overwrite what Apache did?

It also says gethostbyaddr() is not working. I don't know why. It seems
to work when the script is called from the browser.
I'm getting this, which confirms success but also has error messages:

Content-type: text/html
X-Powered-By: PHP/4.3.2
Set-Cookie: machineId=2173643fecddb17b14e53376e348e98c; expires=Sun,
16-Apr-2006
23:00:40 GMT

<br />
<b>Warning</b>: gethostbyaddr(): Address is not a valid IPv4 or IPv6
address in
<b>/home/httpd/vhosts/autostratus.com/httpdocs/tagIndexLibrary.php</b>
on line <b>74</b><br />
<br />
<b>Warning</b>: chmod(): Operation not permitted in
<b>/home/httpd/vhosts/autostratus.com/httpdocs/tagIndexLibrary.php</b>
on line <b>1530</b><br />

<p><a href="rss/music.xml">We just created the file rss/music.xml</a>
<br />
<b>Warning</b>: chmod(): Operation not permitted in
<b>/home/httpd/vhosts/autostratus.com/httpdocs/tagIndexLibrary.php</b>
on line <b>1530</b><br />

<p><a href="rss/critical_mass_consciousness.xml">We just
created the file rss/critical_mass_consciousness.xml</a>
<br />
<b>Warning</b>: chmod(): Operation not permitted in
<b>/home/httpd/vhosts/autostratus.com/httpdocs/tagIndexLibrary.php</b>
on line <b>1530</b><br />

Dec 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chase | last post by:
I'm working in ASP.NET 2.0 and am having problems with some client side script on my .aspx pages. The script looks like this: <script language=vbscript> function OpenFile(FileToOpen) Set...
1
by: Nathan | last post by:
This may be a basic task to some of you perl guru's, but I have a problem getting a perl script i've written, when executed by httpd, to send out an e-mail. Basically, i have a few variables...
2
by: boytheo | last post by:
Hi people, I'm trying to get a script to create a few directories on a webserver, and unzip a file or two. my script works fine locally, when accessed via shell. When accessd via apache, it...
2
by: peteinglastonbury | last post by:
I'd be most grateful if someone would help me. I hope I'm in the right forum (apologies if not) - I'm not sure whether my problem is CGI or Javascript related. I found a script called...
10
by: gh | last post by:
I have a short JS program that runs fine from the command line: #!/usr/bin/java org.mozilla.javascript.tools.shell.Main print("Hello World"); I saved it as HelloWorld.js. (It's the shabang...
2
by: Michael George Lerner | last post by:
Hi, (Python 2.5, OS X 10.4.10) I have a program called pdb2pqr on my system. It is installed so that "pdb2pqr" is in my path and looks like: #\!/bin/zsh -f /sw/share/pdb2pqr/pdb2pqr.py "$@"...
1
by: pssraju | last post by:
Hi, I am not sure whether I am posting it in right location as i cant see any shell scripting forum here. Below script works perfectly fine from command line, but when I run through browser I am...
2
by: smitanaik | last post by:
i have a java file which i am running through shell script. the syntax that i have used is #! /bin/bash javac Copy.java
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.