Solved

setup a cron to run php script

Posted on 2006-11-06
13
240 Views
Last Modified: 2010-04-20
hello,
how can I setup a cron to run this php script every hour

http://domain.com/tutorials/?page=check&id=510540
0
Comment
Question by:Sabrin
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17879728
In /etc/crontab
0 * * * *  /path/to/script
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 17879786
run 'crontab -e', then add following line
0 * * * * /usr/bin/php /path/to/script.php
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879794
Ups - sunnycoder was faster - but in fact little too short.
php scripts usually are written in such way, that they can't be run from command line like: ./script.php
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17879801
Not even with #! ? ... I am indeed ignorant about PHP
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879812
Yeap - php wos not really designed to be used in commandline scripts. Therefore php will dosplay the
#!/usr/bin/php
as it's first output - LOL !
It can be avoided/workarounded - but common users simply start the script from "<?php"
0
 
LVL 14

Expert Comment

by:ygoutham
ID: 17879813
all you need to do is

php /path/to/my/script.php

this line needs to go into crontab.

ravenpl has just hit it on the head.  just ensure that you run it that way or you can do the alternate way

you can do

wget http://youhost.ip.com/path/to/script.php

that can also be added to the script.  Only hitch being that the downloaded files are saved in /root/ directory which might require a clean up.

g
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 14

Expert Comment

by:ygoutham
ID: 17879816
the wget command can be put into the crontab and you can pass on any value depending on the script.  you can include the command straight into the crontab file or can put that into a shell script and add the same to the crontab.
0
 
LVL 14

Expert Comment

by:ppfoong
ID: 17879828

In my own practise, I run it this way:

0 * * * * /usr/bin/php -f /path/to/script.php

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17879835
that was informative .. thanks ravenpl
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879844
-f is optional - but maybe it's more clear what's happening?
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 17879849
make it easy, out in cron a wget:
0 * * * * wget http://domain.com/tutorials/?page=check&amp;id=510540
so you are sure, that apache (or your webserver) will do the job, in some context that is better.
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 17879850
sry didnt read the comment of ygoutham. he is right
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17879855
_iskywalker_: don't parrot ygoutham's responces. Especially suggesting wrong code. In Your example You need
0 * * * * wget "http://domain.com/tutorials/?page=check&amp;id=510540"
Figure out by Yourself - why.

BTW: wget is good sollution, IF the script is put on some website. otherwise no bonus :(
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

16 Experts available now in Live!

Get 1:1 Help Now