Calling a PHP script from cron


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Calling a PHP script from cron
# 1  
Old 06-04-2004
Calling a PHP script from cron

This is a line from my crontab:

12 12 * * * /home/users/ElburdNDL/www/backups/adddate.php

The permissions of the script is 755 it should execute ok....but it doesn't.

Do I somehow have to give cron the path to PHP or something?

If so, how exactly? Thanks.

Ed

PS Am a total newbie to Linux..
# 2  
Old 06-04-2004
Re: Calling a PHP script from cron

Try instead

Code:
12 12 * * * php /home/users/ElburdNDL/www/backups/adddate.php

(or possibly add the path to php before "php")

Quote:

The permissions of the script is 755 it should execute ok....but it doesn't.

Giving an executable permission is not enough. An executable script needs a line at the top which indicates the interpreter to use. For Perl, this is like

#!/usr/bin/perl

For php, very likely it's

#!/usr/bin/php

if you would like to invoke the php script without calling php directly. This seems to work on my system with a simple test.

By the way, I think it would have been more coherent if you continue with your previous thread rather than starting a new one.
# 3  
Old 06-05-2004
Many thanks - that did it!

Ed
# 4  
Old 06-06-2004
Perl

In the same sense as above, would a perl execution look like

12 12 * * * perl /path/to/script.pl

Or would the #!/usr/bin/perl line of the script suffice?

THanks,
Ed
# 5  
Old 06-06-2004
If you explicitly invoke perl or (or just any interpreter) to execute a script, as in "perl script.pl", script.pl needs not be given executable permission to run at all.

If you would like to directly invoke the script, e.g. "./script.pl", the file needs the top #! line in order to tell which interpreter to use to execute it, and the file needs to have executable permission set.
# 6  
Old 06-06-2004
Thanks.

I've tried both:

PHP Code:
12 12 * * * perl /home/users/ElburdNDL/www/cgi-bin/script.pl 
and

PHP Code:
12 12 * * * /home/users/ElburdNDL/www/cgi-bin/script.pl 
(the latter having the #!/usr/bin/perl -w first line)

and neither work Smilie

What's wrong?

Calling the php script now works fine..!

E

PS As an adition, the script works fine when run through IE..

Last edited by eludlow; 06-06-2004 at 08:43 AM..
# 7  
Old 06-06-2004
Ok. You need to learn how to troubleshoot a problem, step by step. Don't jump too far at a time or you'd easily lose track.

First, neglect the cron. Make sure you can run the script on the command line. i.e. run

Code:
perl /home/users/ElburdNDL/www/cgi-bin/script.pl

and look at the output. See if that gives what you expect.

If this is not ok, what is the error? To help others diagnose you need to give further details.

Before you are sure the script runs ok, do not put it for use with cron as it is not going to work either.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

2. Web Development

Permission problems calling Ruby from php script

I'm just getting my feet wet with web development, so hopefully this is a simple thing I'm overlooking, but so far I'm stumped. I have a php script that calls Ruby via exec(). This works fine in my test environment, but when I moved it to my production environment I run into a permissions... (7 Replies)
Discussion started by: dantes990
7 Replies

3. Shell Programming and Scripting

calling a php file from perl script..

Hi am new to perl script .. i need some useful tutorials links to learn perl script.. and a sample script to call a php file from perl script.. thanks.. (3 Replies)
Discussion started by: senkerth
3 Replies

4. Shell Programming and Scripting

calling expect script in ksh is failing via cron

I'm calling an expect script via a ksh script in cron and it is failing. The script runs fine if i run it manually. Does anyone know if it is an issue with compatibilty and if there is a way around it? (2 Replies)
Discussion started by: bhatia
2 Replies

5. Shell Programming and Scripting

Calling php from shell script

Maybe someone here can help out. I have a script cat <somefile> | while read hostname do /usr/bin/php <some php script> $hostname done This script works great for the first entry in the host list. However it will only execute and ignores the loop part. It's almost as if it loses... (4 Replies)
Discussion started by: dbakyle
4 Replies

6. Shell Programming and Scripting

Calling an Expect script from a Webpage using PHP

I have a webpage that is in HTML and PHP. In PHP I have tried using exec, system, shell_exec and passthru functions to call an Expect Script file (temp.exp). This Expect file spawns a telnet session that uses "expect/send" commands to retrieve information from an environmental unit (not a normal... (0 Replies)
Discussion started by: CCUSmith
0 Replies

7. Shell Programming and Scripting

Calling a shell script from php

Hi, I have a shell script and I'm trying to execute it from my php script. The command I'm using is: shell_exec("Script.sh"); Is this correct? It seems to not do anything for me. Not sure if this might be a permission issue or not. I have both scripts 777 permissions. Maybe I got the... (1 Reply)
Discussion started by: eltinator
1 Replies

8. UNIX for Dummies Questions & Answers

Questions about cron and php script

I'm trying to set up a php script that runs via crontab on a server. I've never done anything like this before. My questions: 1) I want the crontab to run the script everyday from 3:58 PM to 4:13 PM EST. How is that written in crontab? 2) The command I want crontab to run is: php -q... (3 Replies)
Discussion started by: colin72
3 Replies

9. Shell Programming and Scripting

Issue calling scripts through CRON.

I have the following cron job in the crontab. #! /bin/bash 25 15 * * 1-5 /export/home/svittala/scripts/scpt1.sh >/dev/null 2>&1. The problem that I am facing is - the scpt1.sh can be executed manually. But, it is not executing through CRON. Not sure what's the issue. Any hints?. Thanks.... (5 Replies)
Discussion started by: vskr72
5 Replies

10. Shell Programming and Scripting

java errors when calling from cron

I am more or less new to using cron, and I am trying to automate a log cleaning system I have made. The system basically cleans through WWW logs that are mounted on an NFS and creates text files for entry into a local PostgreSQL DB. For the past year I have been running the various scripts and... (3 Replies)
Discussion started by: mntamago
3 Replies
Login or Register to Ask a Question