Author Topic: Cron Job  (Read 707 times)

0 Members and 1 Guest are viewing this topic.

Offline Otis

  • (aka Paul)
  • Forecaster
  • *****
  • Posts: 756
    • Lake Huron Weather
Cron Job
« on: June 01, 2024, 05:53:19 AM »
I just had to change my web hosting company and have a few issues with my web site now, one is the cron job for nws alerts.  I had it running just fine on my previous host but not the new host (ICDSOFT).

According to the host (ICDSOFT), to use a cron job to run a PHP script I MUST include this code at the very beginning of the script: #!/usr/local/bin/php.cli

Specifically, this is what the Host states - "In case you use a PHP cron script, please set its first line to: #!/usr/local/bin/php.cli ".

So when trying to use a cron to run "nws-alerts.php" with that line of code added I get the following error:

#!/usr/local/bin/php.cli
Warning: session_start(): Session cannot be started after headers have already been sent in /home/lakehuronweather/www/www/Settings.php on line 388

Without that code added the cron job won't run and tech support verified it needed to be added.

Where I live I really like to have alerts for the surrounding counties and the cron job was the best way to go.  As of now I reduced the codes to 4 until I can get it sorted.

Any help will be appreciated and thanks.
CW3699

Offline hymrog

  • Senior Member
  • **
  • Posts: 58
    • Gahanna Weather
Re: Cron Job
« Reply #1 on: June 01, 2024, 06:28:04 AM »
Hi

Running my site on ICDSOFT.  Try using #!/bin/bash at the top of your script.  Also confirm you have the correct location/path of the script you are running.

g

Offline Otis

  • (aka Paul)
  • Forecaster
  • *****
  • Posts: 756
    • Lake Huron Weather
Re: Cron Job
« Reply #2 on: June 01, 2024, 08:47:14 AM »
No did not work, similar error.
CW3699

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9559
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job
« Reply #3 on: June 01, 2024, 09:18:44 AM »
Try using this for the cron command:

Quote
cd /home/lakehuronweather/www/www;/usr/local/php81/bin/php -q nws-alerts.php > nws-status.txt 2>&1

Most cron instances use a shell as the default for the command execution, and those two commands (cd and php) should be honored in any shell.
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 Otis

  • (aka Paul)
  • Forecaster
  • *****
  • Posts: 756
    • Lake Huron Weather
Re: Cron Job
« Reply #4 on: June 01, 2024, 10:20:32 AM »
Thanks for the input Ken but no joy.
This is not accepted to create the cron job.
Says file does not exist.
CW3699

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9559
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job
« Reply #5 on: June 01, 2024, 01:24:06 PM »
Hmmm... according to the docs for cron at icdsoft ( https://www.icdsoft.com/en/kb/view/1496_cron_jobs_2 ), you should be able to run a bash script.

Cron requires 2 things:
1) the text file has only new-line (\n) characters as line endings.  Windows uses carriage-return,new-line (\r\n) line endings and Macs use carriage-return (\r).  Make sure your text file has proper line endings.
2) the script has to be executable.. using ssh, do a

chmod +x {scriptname}

then change the cd and php command entries in the bash script to the ones needed by icdsoft.
Quote
#!/bin/bash
cd  /home/lakehuronweather/www/www
/usr/local/bin/php.cli nws-alerts.php > nws-alerts-status.txt 2>&1
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 Otis

  • (aka Paul)
  • Forecaster
  • *****
  • Posts: 756
    • Lake Huron Weather
Re: Cron Job
« Reply #6 on: June 01, 2024, 05:04:17 PM »
Ken, I'll get into this again later, I need a break from moving my site/email to a new host.
In the morning I'll try your latest suggestion.  As always, thank you for your time.
CW3699

Offline Otis

  • (aka Paul)
  • Forecaster
  • *****
  • Posts: 756
    • Lake Huron Weather
Re: Cron Job
« Reply #7 on: June 02, 2024, 09:35:32 AM »
So, I downloaded a fresh copy of the alerts script and then asked tech support (ICDSOFT) if they could sort this out.
Looks like they did and it appears to be working.

Thanks to all that provided input/support, I appreciate your efforts  =D>
CW3699

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9559
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job
« Reply #8 on: June 02, 2024, 10:39:18 AM »
You're very welcome.  Glad it's sorted out now.
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