19

I wish to fetch content from a PHP script on my server two times a day, altering a query variable lang to set what language we want, and save this content in two language specific files. This is my crontab:

*/15 * * * * ~root/apache.sh > /var/log/checkapache.log
10 0 * * * wget -O /path/to/file-sv.sql "http://mydomain.com/path/?lang=sv"
11 0 * * * wget -O /path/to/file-en.sql "http://mydomain.com/path/?lang=en"

The problem is that only the first wget command line is being executed (or to be precise: the only file that is being written is /path/to/file-sv.sql). If I switch the second and the third row, /path/to/file-en.sql gets written instead. The first line always runs as expected, no matter where it is.

I then tried using lynx -dump "http://mydomain.com/path/?lang=xx" > /path/to/file-xx.sql to no avail; still only the first lynx line executed successfully. Even mixing wget and lynx did not change this!

Getting kinda desperate! Am I missing something? There are thousands of articles on crontab (combined with) wget or lynx, but all seems to cover basic setups and syntax. Does anyone got a clue of what I am doing wrong?

Thanks,
Alexander

5 Answers5

50

Try adding newline at the end of your crontab.

imax
  • 2,351
3

I just spent some time trying the above answers (adding newlines, deleting newlines, etc.) on a system running cronie. Finally found there is a bug in cronie 1.5.3 that only executes the first cron job for each user. It's fixed in 1.5.4

https://github.com/cronie-crond/cronie/issues/30

Hope this saves someone some time...

Jeroen
  • 31
  • 1
2

There's something about the text that's wrong. Edit your crontab in vim then show invisible characters.

:set invlist

You should be able to see and then correct it.

bahamat
  • 6,433
1

Try add redirect, to debug crontab(or read root mail):

11 0 * * * wget -O /path/to/file-en.sql "http://mydomain.com/path/?lang=en" > /tmp/crontab_ouptput 2> /tmp/crontab_error

Also run 'wget -O /path/to/file-en.sql "http://mydomain.com/path/?lang=en"' from console.

Also use 'crontab -e' for validation new crontab.

Also, try delete not working line and retype it from keyboard.

Backup corntab and run command:

crontab -l | crontab -
alvosu
  • 8,595
0

I also met with the same problem today. I found that it's caused by my server not using the same timezone I am at.

I fixed it by changing the timezone on the server (CentOS 7) with the command:

timedatectl list-timezones
timedatectl set-timezone <My timezone>
Zidong
  • 1