Koozali.org: home of the SME Server

Legacy Forums => General Discussion (Legacy) => Topic started by: darren on October 29, 2002, 10:23:37 AM

Title: run a php script from the cron.daily
Post by: darren on October 29, 2002, 10:23:37 AM
how do i run a php script from the cron.daily folder.
Mainly because i have written a script which alters a mysql database periodically
and it needs to be run daily.
any help would be greatfull.
Title: Re: run a php script from the cron.daily
Post by: Nathan Fowler on October 29, 2002, 05:20:10 PM
Easiest way I do it:

Place security on the PHP script so only localhost (127.0.0.1) can use it.  Place the script on your website some place, with no links to it.

Create a cron.daily file:

pico -w mysql.alter
#!/bin/bash
/usr/bin/lynx --dump "http://www.mydomain.com/url-to-php/altermysql.php" > /dev/null
[SAVE CHANGES]

chmod 755 mysql.alter

That's the easier way to do it, because PHP is installed as a module you won't be able to execute command-line PHP functions, however, you can always use lynx to access the URL on the webserver and thus trigger the PHP code.  As long as you create security inside your PHP code you can avoid security issues.

IE:

if ($password != "l3tm31n")
  exit;

Then you would supply the following URL when using LYNX:
/usr/bin/lynx --dump "http://www.mydomain.com/url-to-php/altermysql.php?password=l3tm31n"

Hope this helped,
Nathan