Author Topic: Cron Job log file  (Read 2290 times)

0 Members and 1 Guest are viewing this topic.

Offline Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Cron Job log file
« on: July 19, 2018, 01:06:47 PM »
Hi All

I'm trying to figure out why my website status (http://moodyweather.ca/wxstatus.php) is throwing a 404 Not Found error when I click on the 'View Log' link.

Looking at my cron job, it's working properly (/usr/bin/php -q $HOME/public_html/saveYesterday.php >/dev/null 2>&1), thanks to ken for helping me with that.

What I don't understand is that the command is pointing directly to the php file, not the cron-yday.txt file, which contains the actual naming for the log file as well as where the log file is supposed to be created.  I don't see anything in the php file that references the txt file to tell it to actually create the log file (which doesn't exist in the cache directory).  The php file does reference the Settings.php file which has a setting for where the cache directory is, but that's it.

If the saveYesterday.php file doesn't look at the cron-yday.txt file, how is it supposed to create the log file that is linked to on the Status page?    :?:



Offline Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #1 on: July 25, 2018, 03:13:23 PM »
So looking at the cron-yday.txt file, I'm wondering if the problem why it's not creating a log file, thus throwing a 404 Not Found error, is that I may have my HDIR information wrong.  Here's the pertinent script info:

# --- begin settings
HDIR="$HOME/<directory name>/public_html/"
SCRIPT=saveYesterday.php
URL="http://www.moodyweather.ca/$SCRIPT"
PHPcmd=/usr/bin/php
CURLcmd=/usr/bin/curl
USECMD=PHP
# --- end settings

Should it read HDIR="$HOME" instead of what it currently has?

Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job log file
« Reply #2 on: July 25, 2018, 11:57:45 PM »
Likely it should read HDIR="$HOME/public_html/" for your site.   The $HOME would be replaced by the shell with /home/d6bsim7o954q as shown in check-fetch-times.php?show=info which shows
Quote
PHP Version: 7.2.6
Document root: /home/d6bsim7o954q/public_html
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 Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #3 on: July 26, 2018, 11:56:43 AM »
I made the change you mentioned, but it still doesn't seem to be working, I still get the 404 error, and there is no log file in the cache directory.  I logged into CPanel on GoDaddy to poke around a bit more and I'm going to try changing the URL line to only be "www.moodyweather.ca/$SCRIPT" (removing the http:// part).  I don't know if that will make any difference, but nothing is making sense as to why it's not working, so I'm throwing mud until something sticks.  :)


Offline Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #4 on: August 09, 2018, 12:50:59 PM »
So one thing or another keeps bringing me back to this issue.

Two things popped into my head that I'd like to clarify that may be causing this to not work right:

1 - I have my Host set to PHP v7.2.  Could that be the issue?  Should it be a lower version?
2 - The permissions on the /cache directory is as follows: User (Read/Write/Execute), Group (Read/Execute) and World (Read/Execute).  Is that sufficient?


Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job log file
« Reply #5 on: August 09, 2018, 05:50:33 PM »
Because your cron command is
Code: [Select]
/usr/bin/php -q $HOME/public_html/saveYesterday.php >/dev/null 2>&1 then no log file will be created/used.   The output of the script goes to /dev/null (the digital wastebasket).

To get the log file, you have to run the cron-yday.txt bash script.  The log file is not really essential to operation.. the status indicator is enough to show the cron is successfully capturing your yesterday data for display.

The scripts work fine with PHP 7.2, so stay with that version.

The exact settings needed for the ./cache/ directory vary from server to server (since various hosters change what setups they use).
Running check-fetch-times.php?show=info on your site shows
Quote
Settings.php Cache file directory in $SITE['cacheFileDir']='./cache/' exists, with permissions=drwxr-xr-x [0755]
..Wrote 104 bytes to ./cache/test.txt successfully, then deleted test file. Cache directory is fully functional.

so your cache directory is working fine and 755 permissions is ok.

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 Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #6 on: August 09, 2018, 06:25:41 PM »
Because your cron command is
Code: [Select]
/usr/bin/php -q $HOME/public_html/saveYesterday.php >/dev/null 2>&1 then no log file will be created/used.   The output of the script goes to /dev/null (the digital wastebasket).

To get the log file, you have to run the cron-yday.txt bash script.  The log file is not really essential to operation.. the status indicator is enough to show the cron is successfully capturing your yesterday data for display.

Ummm... that's the command you told me to put in.   :oops:  (http://www.wxforum.net/index.php?topic=34662.0

How do I get it to run the text file?  Would I just replace 'saveYesterday.php >/dev/null 2>&1' with 'cron-yday.txt'?  That file seems to call the script and has a command to create a log file inside it.

Yeah, I know the log file isn't important... but that 404 page really skews my OCD!   :lol:

Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job log file
« Reply #7 on: August 10, 2018, 12:04:31 AM »
Ok, don't want to skew any OCD :)

Try
Code: [Select]
cd $HOME/public_html;/usr/bin/php -q saveYesterday.php >> ,/cache/saveYesterday.php.txt 2> /dev/null
for the cron command.
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 Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #8 on: August 10, 2018, 06:03:43 PM »
Ok, don't want to skew any OCD :)

Try
Code: [Select]
cd $HOME/public_html;/usr/bin/php -q saveYesterday.php >> ,/cache/saveYesterday.php.txt 2> /dev/null
for the cron command.

So I've copied the line in you provided into my cron job section. Now I wait until tomorrow to see if it worked.  [-o&lt;   :mrgreen:

Just as information, GoDaddy's cron job page:
---------------------------------
PHP command examples:

General example:
 /usr/local/bin/php /home/<uniqueID>/public_html/path/to/cron/script

Domain-specific example:
 /usr/local/bin/ea-php56 /home/<uniqueID>/domain_path/path/to/cron/script

In the above example, replace “ea-php56” with the PHP version assigned to the domain you wish to use.
---------------------------------

Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job log file
« Reply #9 on: August 10, 2018, 06:26:44 PM »
Ok.. try this instead.  There was a , (comma) instead of a . (period) in the above example.. sorry.

Code: [Select]
cd $HOME/public_html;/usr/local/bin/php -q saveYesterday.php >> cache/saveYesterday.php.txt 2> /dev/null
This has TWO commands in it.  A cd to change the working directory to your document root, then a command to have php run the saveYesterday.php script and put the output in cache/saveYesterday.php.txt (so it will show in the 'log' link on the status page).

The GoDaddy examples only have one shell command per cron job.. using the ; (semicolon) causes the cron shell to execute TWO commands for the job.

The cd $HOME/public_html is needed to have the cron shell change to the directory where the script resides.  Without it, the script executes in your $HOME directory only.
« Last Edit: August 10, 2018, 06:31:34 PM by saratogaWX »
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 Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #10 on: August 10, 2018, 06:38:25 PM »
Ok.. try this instead.  There was a , (comma) instead of a . (period) in the above example.. sorry.

Code: [Select]
cd $HOME/public_html;/usr/local/bin/php -q saveYesterday.php >> cache/saveYesterday.php.txt 2> /dev/null
This has TWO commands in it.  A cd to change the working directory to your document root, then a command to have php run the saveYesterday.php script and put the output in cache/saveYesterday.php.txt (so it will show in the 'log' link on the status page).

The GoDaddy examples only have one shell command per cron job.. using the ; (semicolon) causes the cron shell to execute TWO commands for the job.

The cd $HOME/public_html is needed to have the cron shell change to the directory where the script resides.  Without it, the script executes in your $HOME directory only.

Interesting.  I tried looking up information on what the -q flag does, but couldn't find anything helpful.  Sure is different from the old DOS days!   :shock:

Strange how, in CPanel, I can't see any of this '/usr/local/bin/'.  I also can't find that .htaccess file mentioned in another thread, even though I have it showing hidden files.  I wonder if GoDaddy has their stuff set up differently than other hosts, or if it's at a different level I can't access?


Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job log file
« Reply #11 on: August 10, 2018, 07:02:20 PM »
The '-q' argument on a php command is for the CLI (command line interface) version .. it tells PHP to not emit HTML headers.. just the print/echo outputs.

PHP CLI docs at http://php.net/manual/en/features.commandline.options.php  I find it useful to have a Windows Help version on my system.. you can download from http://php.net/download-docs.php (I use the .chm version).

You may not be able to see .htaccess in your File Explorer in Windows if you have Hide Extensions turned on.

Yes, GoDaddy does have the setup of the filesystem different from other hosters.. they all have their own ways of doing user filesystem addressing.  The $HOME shell variable always has the full filesystem path to your home directory.  Some hosters have $HOME/public_html as the root for the webserver, others use $HOME/www or $HOME/httpdocs .. it varies from hoster to hoster.

Likewise, each hoster has their own placement for the PHP interpreter .. /usr/bin/php, /usr/local/bin/php, /usr/bin/php7 (etc) .. you have to find that out based on their docs or a quick call to their tech support.  You won't be able to see any /usr/local/bin stuff via FTP as your FTP 'home' is likely fixed to $HOME.  To see other directories, you'd have to use SSH to connect to the webserver itself, then a shell ls command to list other stuff (but you may not have permissions to see stuff outside your $HOME directory for security reasons).  Using SSH, I find that (sometimes) a 'whereis php' will show the locations for the PHP interpreter (usually).  The definitive answer should be obtainable from the tech support from your hoster.

Lastly, shell scripting (sh) used by cron is similar to (but not the same as) Windows DOS/batch files .. and, there are multiple shells sh, bash, tcsh, csh available on multiple platforms.. each with a similar language, but different.  Generally, cron will use sh syntax/commands.
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 Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #12 on: August 10, 2018, 07:14:57 PM »

You may not be able to see .htaccess in your File Explorer in Windows if you have Hide Extensions turned on.


Hmmmm... I generally use the GoDaddy CPanel interface, which has a File Explorer function.  I can see quite a few .xxxx files on the root of public_html, but no .htaccess.  Perhaps I should contact GoDaddy about it and see where it is.

But this is info for a different thread.   :grin:

Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job log file
« Reply #13 on: August 11, 2018, 11:17:07 AM »
So, I checked this morning on your wxstatus.php page, and the cron worked, but... the logfile I'd misnamed in the last command.
You can see it ran at http://www.moodyweather.ca/cache/saveYesterday.php.txt .. however, the view log link is looking for LOG_saveYesterday.php.txt file. 

So, use this for the cron command instead
Code: [Select]
cd $HOME/public_html;/usr/local/bin/php -q saveYesterday.php >> cache/LOG_saveYesterday.php.txt 2> /dev/null and all should be correct tomorrow morning.

BTW.. you can use the cPanel file manager to rename cache/saveYesterday.php.txt to cache/LOG_saveYesterday.php.txt and the current log will display correctly on your wxstatus.php view log link.
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 Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #14 on: August 11, 2018, 12:23:42 PM »
So, I checked this morning on your wxstatus.php page, and the cron worked, but... the logfile I'd misnamed in the last command.
You can see it ran at http://www.moodyweather.ca/cache/saveYesterday.php.txt .. however, the view log link is looking for LOG_saveYesterday.php.txt file. 

So, use this for the cron command instead
Code: [Select]
cd $HOME/public_html;/usr/local/bin/php -q saveYesterday.php >> cache/LOG_saveYesterday.php.txt 2> /dev/null and all should be correct tomorrow morning.

BTW.. you can use the cPanel file manager to rename cache/saveYesterday.php.txt to cache/LOG_saveYesterday.php.txt and the current log will display correctly on your wxstatus.php view log link.

Thanks Ken.  I just noticed that now to.  I checked and the status was current, I clicked on the link and it 404'd on me.  I laughed good.  :lol:  I noticed the name was off.  No biggy.  I'll change it as you suggested.
Thanks for checking in on that.   UU

Offline Stryder87

  • Senior Member
  • **
  • Posts: 70
    • Moody Weather
Re: Cron Job log file
« Reply #15 on: August 12, 2018, 11:45:56 PM »
It's run a couple times now and it seems to be working just fine.

I will admit, when I clicked on it the first time it worked I was a little surprised at what was there.  Just a line saying it was done and cached to a text file.  I actually cocked my head and said, "That's it?"   :lol:  I guess what I was expecting was a formatted line of the actual data it had recorded or something.  So I looked at the file it had made and was overwhelmed with a wall of text.  BUT... it's a good thing!  I think that was the data I was kind of expecting... although I'm not entirely sure what it all was that I was looking at.   :grin:

And, it makes me wonder if my thoughts on using that data somehow to build a Historical Information page (I mentioned it in this thread: http://www.wxforum.net/index.php?topic=34887.0) is possible?

Has anyone done this somehow?

Online saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Cron Job log file
« Reply #16 on: August 13, 2018, 12:31:15 AM »
 \:D/ Glad it's all sorted out now
You should only see one new line in the LOG file per day (saying it was done, or an error message if there was a problem).

Yes, that funny named 'yesterday' file contains the $WX[] array of all the values from your station at 23:58 local time yesterday.  The odd contents are from a PHP serialize() function which unloads an array into a long string of characters.
The template uses a unserialize() to reconstitute it into a 'yesterday' array and pick some data to display on the index page (yesterday high/lows).

The Ambientweather.net site does offer graphs with historical data for your station, but I've not looked into what it would take to port something like that to the template set.
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