473,799 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 `"tagIndexLibra ry.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 2159
On 21 Dec 2005 09:06:53 -0800, "lawrence k" <lk******@geoci ties.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.u k :: 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************ *********@g49g2 000cwa.googlegr oups.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 `"tagIndexLibra ry.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****@larseigh ner.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******@geoci ties.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_TRANSLATE D"] /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******@geoci ties.com> wrote:
Andy Hassall wrote:
On 21 Dec 2005 09:06:53 -0800, "lawrence k" <lk******@geoci ties.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_TRANSLATE D"] /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.u k :: 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****@sbcglob al.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.u k :: 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************ **********@g49g 2000cwa.googleg roups.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******@geoci ties.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_TRANSLATE D"] /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****@larseigh ner.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

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

Similar topics

2
1209
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 oShell = CreateObject("WScript.Shell") oShell.Run("explorer " & FileToOpen) end function </script>
1
3058
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 passed into this script, it writes them to a a database, and then its supposed to read the "E-mail list" attached to that database entry and shoot an e-mail off to everyone in that list letting them know that there's been an update. I have what...
2
1966
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 fails :( What to do?
2
2191
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 BatmoAudiopop.js which opens a pop-up browser window with an audio player when a link is clicked. Basically, it sets the right mime-type depending on the operating system and audio file type, then opens a window with the audio file (passed as a parameter) in...
10
8336
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 that makes it a JavaScript program, not the .js.) However, if I start it from Safari or Firefox, I get the following message in the log:
2
7580
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 "$@" When I call it via this script:
1
4407
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 not getting anything inside my $dt. Because of this its always going inside failure scenario. My procedure is going to return either Success / Failed output. Can anybody tell me where I am messing up. #!/usr/bin/ksh if then ...
2
3252
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
6240
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 this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10252
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10231
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.