[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-users] PHP and crontab



Dan <dan@xxxxxxxxxxxxx> wrote:
> [admin admin]$ curl http://www.domain.com/cgi-bin/script.cgi
> bash: curl: command not found

I haven't gotten around to installing curl, though I've heard good things about it.
I do run scripts from cron using wget and php, though (and I have used lynx to do the
same also and it's also easy to install).  Here's a line from a user crontab:

10      05      *       *       *       wget -q --spider host.domain.com/script1.php
> /dev/null 2>&1

wget is easy to install.  It's used to retrieve files from the web.  In the example
above, the cron entry runs at 5:10 am and triggers wget to access the webpage using
the --spider flag which tells wget not to download anything.  "> /dev/null 2>&1"
ensures that there is no output.  This particular script runs a MySQL query and
emails a recipient if certain criteria is met.  Warning: if you want to ensure no one
else can run your script from the web it's a good idea to use an .htaccess file.
wget has flags to set the http user and password.  In the example above it's not
critical that I do so, but in other scripts I run it is.

Here's another cron entry that runs every file found in
/home/sites/site12/master/106012/cron.daily daily at 4:30 am.  There are a few files
within that directory and they are all php files with permissions of 700 and owned by
the same owner as the crontab entry that calls them.  The php files are executed from
the command line b/c each file contains "#!/usr/local/phplocation/bin/php" (the
location of my php binary) and I have PHP configured as a binary to do this.  PHP
*must* be compiled as a binary to execute the files from the command line (versus
over the web).  FYI, the "run-parts" program ensures that *all* of the files in that
directory are executed.

30      04      *       *       *       run-parts
/home/sites/site12/master/106012/cron.daily > /dev/null 2>&1

One of the scripts in this directory is "dir_approval_queue.php4".  If I wanted to
run that file from cron, but none of the others in the directory my cron entry would
look like:

30      04      *       *       *
/home/sites/site12/master/106012/cron.daily/dir_approval_queue.php4 > /dev/null 2>&1

If you get rid of the "> /dev/null 2>&1" piece, the output of the script will be
mailed to the owner of the cron entry.  That may be useful for automated backups so
that you know that they executed.  I hope this is enough to get you on the right
track.

Steven Werby {steven-lists@xxxxxxxxxxxx}