Author Topic: 1and1 cron job help  (Read 1249 times)

0 Members and 1 Guest are viewing this topic.

Offline 96Cobra

  • Member
  • *
  • Posts: 37
1and1 cron job help
« on: July 22, 2018, 09:40:40 PM »
I've decided to add a few more counties to my alerts list.  Since I'm now over 4 zones, I'd like to use a cron job to keep my site from loading slower.  For now, I've disabled the "more than four zones" warning message,  because I'm not sure if I can do the proper cron job.  My host is 1and1 (unlimited plan) and I've used 0 of 500 allowed cron jobs.  When I try to create a cron job, I have to select daily, weekly, or monthly in the control panel drop down box.   Is there some other way to have it run every 5 minutes?

Thanks for any help,
Roger
www.rkb2.com

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: 1and1 cron job help
« Reply #1 on: July 23, 2018, 10:01:41 AM »
I tried to find the old help pages on 1and1 before they had the cron job tool and I end up landing on the German version of their help site...  ¯\_(ツ)_/¯

Anyway, are you familiar with using ssh to access the server? You can set this up under "Manage Webspace". Once you have established a connection to the server, type in "crontab -l" (that's the lower-case letter "L"), hit return, and display what it shows here.

https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: 1and1 cron job help
« Reply #2 on: July 23, 2018, 12:18:47 PM »
I have two different 1and1 account, one Unlimited Pro shared server and one VPS -- neither one show a control panel such as you describe so I can't help with using cron that way -- On my sites, I use SSH to the server, create a text file (with nano) that has entries like

Code: [Select]
*/5 * * * * cd $HOME/httpdocs && /usr/bin/php -q nws-alerts.php > status.txt 2>&1
That code causes cron to change to the directory with nws-alerts in it, then the second shell command runs the nws-alerts.php script and places the listing output in status.txt

save the text file (I called it cronjob.txt), then

crontab cronjob.txt

to enable it then

crontab -l

to list the contents of the cron jobs list.

Several 'gotchas' with cron/linux shell scripting:
1) the files (like cronjob.txt) have to have unix line endings only (LF) and NOT Windows line endings (CR, LF)
2) cron only knows your home directory and you need to change to your document root to have your script run correctly

Hope this helps...
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 Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: 1and1 cron job help
« Reply #3 on: July 23, 2018, 12:36:08 PM »
Ken, it took me a while to find it...

If you go to Hosting, click "More >>".  Then scroll down to "More features" on that page.

(edit: or directly... https://my.1and1.com/cronjobs-overview)
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: 1and1 cron job help
« Reply #4 on: July 23, 2018, 02:26:38 PM »
Wow, that is quite hidden  #-o  :?

I suppose that using the full URL to the nws-alerts.php would do for the 'command' to do.   As I said, I'm using the SSH/crontab method with bash scripts to run the automation on my shared site.
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 saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: 1and1 cron job help
« Reply #5 on: July 23, 2018, 02:43:49 PM »
Ok, I tried creating a job using the 1and1 control panel.  It does work, HOWEVER, it only allows a once-per-day run (no exact time specified) so it is NOT USEFUL for running the nws-alerts.php script (which needs to run every 5 minutes, 24/7).

The only way to do that on a 1and1 shared Linux server is to use the SSH/crontab method I'd outlined above.
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 Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: 1and1 cron job help
« Reply #6 on: July 23, 2018, 02:44:46 PM »
As I said, I'm using the SSH/crontab method with bash scripts to run the automation on my shared site.

Yup - that's what I do also. The control panel thing is fairly new and the cron jobs I have run don't show up there.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline 96Cobra

  • Member
  • *
  • Posts: 37
Re: 1and1 cron job help
« Reply #7 on: July 23, 2018, 07:49:26 PM »
Thank you for the help!  Looks like I'm getting in over my head, but will keep learning/trying until I get it working.  I've used ssh a few times with a raspberry pie, but that's pretty much the extent of my ssh and linux knowledge. Thanks again for the help & I'll probably be back looking for more!

Offline 96Cobra

  • Member
  • *
  • Posts: 37
Re: 1and1 cron job help
« Reply #8 on: July 25, 2018, 03:04:34 AM »
Ken,

I was able to SSH in and create a cronjob (I called it cronjob.txt as well) off of your provided code, but not sure what to do next.  I entered "crontab cronjob.txt" to start it (I assume that's how you start it).  When I enter "crontab -l" I get your
Code: [Select]
*/5 * * * * cd $HOME/httpdocs && /usr/bin/php -q nws-alerts.php > status.txt 2>&1 output.  But where does that status.txt file end up? What do I do next? Still lost, but making progress!

Thanks,
Roger

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: 1and1 cron job help
« Reply #9 on: July 25, 2018, 11:52:02 PM »
The status.txt file would end up in the document root if the command is executing correctly.

To use nws-alerts with a cron job, you have to change nws-alerts-config.php from
Code: [Select]
$noCron        = true;                     // true=not using cron, update data when cache file expires
//                                            false=use cron to update data
to
Code: [Select]
$noCron        = false;                     // true=not using cron, update data when cache file expires
//                                            false=use cron to update data

Then you can see the result in http://www.rkb2.com/status.txt

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 96Cobra

  • Member
  • *
  • Posts: 37
Re: 1and1 cron job help
« Reply #10 on: July 26, 2018, 02:18:17 AM »
That's what I figured, but it's not there. Not sure why, so I'll try it again and see what happens, even though crontab -l shows the same output as your post earlier. Thanks again!

Update...

I created the first one as cronjob.txt. I just created another & called it cronjob.php.  Tried to enable it by "crontab cronjob.php", but still no status.txt file found.  I did find both cronjob files in my my root directory.  Is that where they should be?
« Last Edit: July 26, 2018, 04:58:03 AM by 96Cobra »

 

anything