Hi.
I am having a little trouble with setting up a cron job. Here's the info:
What I'm trying to do:
Using PHP and a MySQL database, I am going to grab information from a
news database with PHP. I want cron to run the php script and then
copy the dumped file to a directory and rename it as an xml file. I
have a news database in MySQL that stores news shorts. The PHP script
will grab the headline, description and link. The script will then
format the output as a valid rss feed. The only problem with this is
that the file will still be .php. This is why I want to run the cron
job.
So, once the script is executed and in valid rss (xml) format, I want
cron to grab the html output, copy it to the proper directory, and
rename it feed.xml.
Now here's the problem.
I have been looking around online and have seen that accomplishing
this task should be very easy. The script is a piece of cake (and I'll
be able to do that in about five minutes), but the cron job is simply
not working. I am using lynx to run the php script. If I am in a
telnet session and run the following command:
lynx -dump http://www.domain.ext/script.php>/www/vhosts/domain.ext/htdocs/feed.xml
everything works perfectly. Lynx runs the script, and cron writes the
file. all is well. But when I try to do it in cron, cron will look
like it's running the script, and will simply create a 0 kb file in
the directory called feed.xml with nothing in it. Note: cron will only
do this when there is no file there already named feed.xml. It won't
overwrite.
Important Info:
Server OS: FreeBSD 4.4
Now, the crontab is set up completely differently than any other os
I've used in the past. Rather than having a cron folder with
cron.daily, weekly, monthly etc., there is just a crontab that points
to other scripts. So here is the crontab, with the last entry the dump
that I'm trying to do.
####################################################################
# /etc/crontab - root's crontab for FreeBSD
#
# $FreeBSD: src/etc/crontab,v 1.21.2.3 2000/12/08 10:56:07 obrien Exp $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#
#minute hour mday month wday who command
#
*/5 * * * * root /usr/libexec/atrun
#
# rotate log files every hour, if necessary
0 * * * * root newsyslog
#
# do daily/weekly/monthly maintenance
1 3 * * * root periodic daily
15 4 * * 6 root periodic weekly
30 5 1 * * root periodic monthly
# time zone change adjustment for wall cmos clock,
# does nothing, if you have UTC cmos clock.
# See adjkerntz(8) for details.
1,31 0-5 * * * root adjkerntz -a
# Clean out the popauth database at 3am
2 3 * * * root /usr/sbin/vcleandb
#test 2
*3 * * * * root /usr/sbin/dump
####################################################################
So, this is how I have the /usr/sbin/dump file set up:
#!/bin/sh
/usr/local/bin/lynx --dump
http://www.domain.ext/script.php>/www/vhosts/domain.ext/htdocs/feed.xml
####################################################################
So to wrap up, the script can run using the above command, but won't
do it in a cron job. Please let me know how I can get the script to
run and how to get it to overwrite when the file exists. I want the
script to run every hour or so, and to overwrite the existing feed
file. I've been working on this for a day now, and I have tweaked so
many different things. If you have any questions, please let me know.
Thanks
Nathan |
Request for Question Clarification by
weaver-ga
on
29 Jan 2004 15:20 PST
I don't have an absolute answer here, but let's run through a few
things and maybe the answer will strike us. You're right in assuming
this should be a pretty simple task to get finished.
First, the only reason other Unixes can do the cron.daily,
cron.weekly, etc. is because they have an entry in their /etc/crontab
file which runs a program called run-parts on the specified directory.
You could do the same on FreeBSD. The run-parts program might not be
installed by default though.
# run-parts
* * * * * root run-parts /etc/cron.minute
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
I don't see anything wrong with the syntax of your lynx command. I
tried it out with a different domain here and it worked fine. You
should be careful naming your script dump. Most Unixes come with a
program called dump that would be in /sbin/dump. But, since you
specify the complete path name, you should be fine there.
I think you have a typo in your crontab file, but I don't think it
should prevent this from working. Your test line starts with *3. My
crontab program ignores the 3 and runs the script every minute. Did
you mean to have */3? Which would run the script every three
minutes?
Make sure /usr/sbin/dump is executable (just covering all the bases).
Make sure you've got the path to lynx correct in the script. If not,
my system creates a 0 byte file just as you are describing. Use
'which lynx' to find the correct path.
This setup should work, there must be some small detail that is being
overlooked on your system. Hopefully this will help you find that
small detail. Let me know if my comments were of any help and I'll
repost this as an answer. If not, let me know and perhaps I can think
of more things to try.
|