Author Topic: NWS Alerts script and Cron Jobs  (Read 1142 times)

0 Members and 1 Guest are viewing this topic.

Offline K6GKM

  • CamWX.com
  • Contributor
  • ***
  • Posts: 125
    • CamWX
NWS Alerts script and Cron Jobs
« on: May 23, 2023, 12:03:40 PM »
Hello everyone,

I've been using cron-job.org for years to execute my nws-alerts,php script, but recently I've had problems with my hosting provider "throttling" access.  I'll frequently get a 403 (Forbidden) error and often times the cron job will shut off due to multiple consecutive failures.  I've also not been able to find a way to white-list cron-job.org's IP addresses.

I figured I could set up a cron job through my hosting provider itself, but I'm running into issues there as well.  I'm trying to set the command "/usr/local/bin/php /hidden/for/privacy/nws-alerts.php" to run every minute (* * * * *).  The cron job itself is running, but the output of the script is odd, as if I have no zones configured:

Code: [Select]
<!-- nws-alerts.php - V1.44 - 13-May-2023 -->
<!-- 0 unique Zone entries found. Zones='' -->
<!-- Cron job enabled -->
<!-- unable to open cache file -->
<!-- unable to open cache file -->
<!-- unable to open big icon cache file -->
<!-- Total process time: 0.0049 seconds -->

It processes fine if I call nws-alerts.php from my browser...  anyone run into this issue before?  Appreciate any help.
Grant Miles
Camarillo, CA, USA
Owner/Admin - CamWX.com
SKYWARN Spotter
Station Hardware: Davis Vantage Pro2 Plus w/ 24hr FARS
Station Software: Weather Display, Weather Message, FWI Calculator, StartWatch, with social media & messaging automation using Make.com, Twilio, and Brevo.


Offline FresnoEddy

  • Member
  • *
  • Posts: 2
Re: NWS Alerts script and Cron Jobs
« Reply #1 on: January 12, 2024, 03:38:06 PM »
I am having this same problem with the nws-alerts.php script, getting the messages "unable to open cache file", etc. Were you able to find a fix for this?

Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9297
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: NWS Alerts script and Cron Jobs
« Reply #2 on: January 12, 2024, 04:20:30 PM »
To successfully run a cron job locally on your webserver, you have to have three things:
1) the full path to the php command for your site (use check-fetch-times.php?show=info to see the PHP full path)
2) issue a change directory (cd) command to your document root (the check-fetch-times.php?show=info shows that also)
3) then you can construct a cron command like
Code: [Select]
cd $HOME/public_html; /full/php/path/php -q nws-alerts.php > nws-status.txt 2>&1 replacing /full/php/path with the path shown in 1) above and public_html with the directory used as your document root (like www, httpdocs, public_html, etc) as shown in 2) above.

Set it to use */5 * * * *  (every 5 minutes) and you're set.

The result of a cron execution should be available in nws-status.txt on your site.

nws-alerts.php won't run correctly without the cd to your document root in the cron command as cron will default to your home/FTP directory, not your document root, so it can't find the other configuration files needed to run.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline FresnoEddy

  • Member
  • *
  • Posts: 2
Re: NWS Alerts script and Cron Jobs
« Reply #3 on: January 12, 2024, 04:49:45 PM »
Thank you, Ken. That worked and now makes sense to me as well! I appreciate your help with this as well as all of your work on the templates.