Cron Issue Reborn

Connect with other users about what to run on your webhosting (and how to run it) here.
Post Reply
tenub
A semi-regular
A semi-regular
Posts: 29
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Tue Aug 27, 2013 6:28 am

Cron Issue Reborn

Post by tenub »

Here is my current crontab:

Code: Select all

MAILTO=""
0 0 * * * mysqldump -uUSERNAME -p'PASSWORD' --all-databases | gzip > ./backup/db.`date +"%Y.%m.%d"`.sql.gz
*/1 * * * * php ./path/to/script1.php
*/5 * * * * php ./path/to/script2.php
*/10 * * * * php php ./path/to/script3.php
0 0 * * * php php ./path/to/script4.php
It does not seem to be executing my scripts every interval they're supposed to execute. What's more is that they seem to rarely be executing. Each script accesses my database, does some manipulation of the data, then stores it in a json file somewhere else on the server. I can tell that the scripts aren't executing nearly as often as they should be because my json file modify dates/times don't update nearly enough. More importantly though, my sql database backup command is simply not executing at all. What's interesting, however, is that if i run the command via SSH it works just fine, ie.:

Code: Select all

mysqldump -uUSERNAME -p'PASSWORD' --all-databases | gzip > ./backup/db.`date +"%Y.%m.%d"`.sql.gz
tenub
A semi-regular
A semi-regular
Posts: 29
Joined: Tue Aug 27, 2013 6:28 am

Re: Cron Issue Reborn

Post by tenub »

After watching the modified dates/times more closely it seems only the first script is running via cron:

Code: Select all

*/1 * * * * php ./path/to/script1.php
User avatar
Spray
Former staff
Former staff
Posts: 630
Joined: Wed Dec 28, 2011 10:41 pm
Location: Oregon

Re: Cron Issue Reborn

Post by Spray »

Have you tried filling in the MAILTO line to include your email, so you're able to check the output of these cron scripts?
User avatar
Edge100x
Founder
Founder
Posts: 13109
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Cron Issue Reborn

Post by Edge100x »

The ones that say "php php" probably wouldn't work for that reason.

Try also editing the crontab with "crontab -e" from the command line. When you exit and save, it should perform superficial checks on the schedule definitions.
tenub
A semi-regular
A semi-regular
Posts: 29
Joined: Tue Aug 27, 2013 6:28 am

Re: Cron Issue Reborn

Post by tenub »

Okay, it looks like replacing the relative paths to my json files in all of my scripts with an absolute path fixed the issue. the only remaining issue is the command to backup my sql db for which i receive the following error via mail (thanks to Spray):

Code: Select all

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
User avatar
Edge100x
Founder
Founder
Posts: 13109
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Cron Issue Reborn

Post by Edge100x »

The backticks are probably doing it. Try placing that command into its own script (like backup.bash) and executing the script instead.
tenub
A semi-regular
A semi-regular
Posts: 29
Joined: Tue Aug 27, 2013 6:28 am

Re: Cron Issue Reborn

Post by tenub »

How can I gain permission to execute the script?
User avatar
Edge100x
Founder
Founder
Posts: 13109
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Cron Issue Reborn

Post by Edge100x »

You should chmod the script to 700.
Post Reply