Avatar of webdesigner_dk
webdesigner_dk asked on

Cron Job that runs php script every hour

Hi,

I need help setting up a cron job on a server. The purpose of the cron job is to run a php script every hour. The script deletes the contents of some tables in a mySQL database.

I have tried to use the following (from this tutorial):

curl -s -o /dev/null http://www.domain.com/cleanup.php?clean=log

Even though the script runs nicely if I run it from a browser manually, the cron job doesn't run the script.

I have another cron job that works:

php -f /var/www/domain.com/public_html/shell/indexer.php -- reindexall >/dev/null 2>&1

I don't have access to the cPanel, so I have to tell my web hosting company to set up the job on the server.

Thanks!

Dio
Scripting LanguagesLinuxApache Web Server

Avatar of undefined
Last Comment
webdesigner_dk

8/22/2022 - Mon
omarfarid

Look into the following when running a crontab job:

1- set the env. variables for the script to run
2- use full pathnames to files and dirrctories
3- redirect output and errors to files that you can check later.
4- specify the shell to use to run the script with.

Do you get any errors while running the crontab job?
ASKER
webdesigner_dk

Thanks for the answer. I get this in the log:

Sep 11 18:05:01 prod9 /USR/SBIN/CRON[18161]: (root) CMD (curl -s -o /dev/null http://www.domain.com/cleanup.php?clean=log)

Any ideas?
omarfarid

I think this means the job was run at that time

but did you try to put the command in a shell script with setting env. variables etc?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
webdesigner_dk

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
webdesigner_dk

My web hosting company managed to solve the problem. They didn't give any details though.