Cron items not properly updating

I recently attempted to move my PWS Dashboard to a new server. I own 3 servers and PWS Dashboard runs correctly on 2 of them. I recently built a third and began hosting my weather site on it. It seemed to work fine except I noticed the min-max temp, max wind gust, etc weren’t being recorded properly.

The only major difference between the new server and the other two is this one is running php8 on Ubuntu 24.04 and the others are php7 on Ubuntu 20.04. Crontab runs PWS_cron_stationcron.php every 2 minutes, nws-alerts/nws-alerts.php every 15 minutes, and my own php script every 5 minutes. Most of it works.

Here’s what is happening.

  • All files in jsondata update correctly
  • All files in nws-alerts/cache update correctly
  • My own files update correctly
  • Files in _my_settings do not update
  • Files in chartsmydata do not update

Interestingly, if I run PWS_cron_stationcron.php manually in the shell, everything updates like it should. It’s only when crontab runs it does it fail to update some files. I’m the owner of all directories and files and chmod is 664 for all files in question.

I haven’t yet dug into PWS_cron_stationcron.php to try altering code to test, but I guess that’s next. Before I do that, I’m hoping someone can offer a solution that I’m not seeing.

If it runs manually then its not the PWS_cron_stationcron.php but what ever is trying to run the PWS_cron_stationcron.php that the issue

If you’re using crontab then you will usually use something like cURL or wget to access the required web page. Perhaps whatever is being used isn’t installed on that server?

IMHO running a (free) external cron-server poses less problems and gives better support when having problems.

As @hcorrin says
If it runs manually then its not the PWS_cron_stationcron.php but what ever is trying to run the PWS_cron_stationcron.php that the issue

Better test your crontab → cron task with the test option.

. . ./pwsWD/PWS_cron_stationcron.php?test

That could give a clue where it fails.

Succes,
Wim

When I try to run PWS_cron_stationcron.php?test it gives me an error

Could not open input file: /var/www/weather/pwsWD/PWS_cron_stationcron.php?test

This is the case whether I run it manually or crontab runs it. Is ?test the wrong argument? Also, running without any argument always returns

success files loaded

One more thing; I just noticed that if I run it from my home directory with php /var/www/weather/pwsWD/PWS_cron_stationcron.php it just gives me that generic response. But when change to the actual directory and run it from there, PWS_cron_stationcron.php I get a much more verbose response. Is that normal?

Sadly the cronfab does niot like the extra URL param.
So that test =can not be used.

That is far to short.
Only the first task “loading of files” is executed.The script runs into an error after that as the output should look like

success files loaded + history was already valid + need upload to others + 0 uploads + no roll-over needed 2025-02-17T18:10:27+01:00


Please test this cron-script PWS_cron_stationcron2.php
It will generate a lot of information and the last line should be the error
PWS_cron_stationcron2.php.zip (7.3 KB)


Why do we not get the URL to your site?
That would help a lot.
This is a URL you used in the past

http://weather.from-oh.com/PWS_cron_stationcron.php?test

Works OK with and without the ?test
Shows multiple problems with accessing your files.

success files loaded <br />
<b>Warning</b>:  file_put_contents(/var/www/weather/pwsWD/chartsmydata/today.txt): failed to open stream: Permission denied in <b>/var/www/weather/pwsWD/PWS_cron_stationcron.php</b> on line <b>168</b><br />
 ! problems with saving data !<br />
<b>Warning</b>:  touch(): Utime failed: Permission denied in <b>/var/www/weather/pwsWD/PWS_cron_stationcron.php</b> on line <b>236</b><br />
PWS_cron_stationcron.php (122) include_once =>PWS_livedata.php
PWS_livedata.php (22) version =>PWS_livedata.php|01|2022-03-28|
PWS_livedata.php (25) include_once =>PWS_settings.php
PWS_livedata.php (29) include_once =>PWS_shared.php
PWS_shared.php (21) version =>PWS_shared.php|01|2021-12-04|
PWS_livedata.php (39) $itsday =1
PWS_cron_stationcron.php (170) Data could not be saved to /var/www/weather/pwsWD/chartsmydata/today.txt
 + history was already valid 
$livedata=/var/www/weather/pwsWD/jsondata/ambient.txt
$hist_file=/var/www/weather/pwsWD/_my_settings/history.txt
 + need upload to others  + 0 uploads  + no roll-over needed 

Succes,
Wim

I think I solved the problem. The issue was concerning which directory the php command is issued from. The cron job fails if I run it normally, */2 * * * * php /var/www/weather/pwsWD/PWS_cron_stationcron.php. But if I change to the directory first, it will run correctly. So, now my crontab says */2 * * * * cd /var/www/weather/pwsWD && php PWS_cron_stationcron.php which now updates files as it should.

Running it as a url like you demonstrated above fails the same way. Here is the response when I run it the new way

success files loaded + data appended to day file + history recalculated + history saved + need upload to others + 0 uploads + no roll-over needed

What still baffles me is why it was updating some files just fine (like the ones in jsondata) but not the history files. I’ll just mention that my crontab runs several php scripts located within the www directory and this is the only one that needs to cd into the directory to make it work…and only on one of my servers. ¯\_(ツ)_/¯

Thanks for your assistance, Wim and others