cron job to run url cpanel
Asked Answered
T

5

9

i need to create cron job to run URL from Cpanel every minute
when i open the link from browser it's auto generate backup for database

i choose the common setting ( once per minute ) * * * * *
and this is the command i use but no one worked

GET http://example.com/backup > /dev/null
wget http://example.com/backup
curl -s http://example.com/backup > /dev/null
wget -q -O /dev/null "http://example.com/backup" > /dev/null 2>&1

this is my references
https://forums.cpanel.net/threads/cron-job-to-call-a-web-page.60253/
Using CRON jobs to visit url?
CRON command to run URL address every 5 minutes

Topcoat answered 18/10, 2016 at 9:47 Comment(4)
Define "no one worked". Did you get an error message? Did you try the commands interactively (instead of having cron execute them) ? Have you tried redirecting the output of your commands to a log file and inspecting it?Irfan
@FrankSchmitt no error message appears i tried the link directly and it's working, how to commands interactively or redirect the output of my commands to log file and inspecting it ??Topcoat
Instead of redirecting the output to /dev/null, redirect it to a log file, e.g. via command > /tmp/cron-log.txtIrfan
@FrankSchmitt thanks for your help, i get the error that code redirect to login page because it's required to be login to create backup , i change auth for it and working :)Topcoat
A
18

use this

wget -q -O - http://example.com/backup >/dev/null 2>&1

instead of

wget -q -O /dev/null "http://example.com/backup" > /dev/null 2>&1
Adduce answered 4/1, 2018 at 7:31 Comment(2)
can we also use like GET https://example.com/billing/?ng=console/0982995697/ ??Biocellate
We had to escape any & characters in the command, e.g., if the URL contains parameters. Maybe just a requirement of a particular version of CPanel. The example then becomes wget -q -O - http://example.com/backup?param=1\&param=2 >/dev/null 2>\&1.Demitria
B
4

Alternative try this

curl -s https://example.com/cron

don't forget to add the HTTP or HTTPS protocolenter image description here

Brose answered 26/12, 2021 at 10:30 Comment(0)
S
2

wget -q -O /dev/null "http://example.com/backup" > /dev/null 2>&1

Strontium answered 2/1, 2019 at 13:30 Comment(0)
S
1

You can use "links" command like:

links https://www.honeymovies.com
Soberminded answered 9/2, 2017 at 5:49 Comment(0)
C
1

For Cron job to work you just need to hit the url, without any output and without downloading anything.

I am using only the wget with this two parameters:

wget -q --spider https://example.com/ 
  • ‘-q’ :Turn off Wget’s output.
  • --spider : When invoked with this option, Wget will behave as a Web spider, which means that it will not download the pages, just check that they are there. For example, you can use Wget to check your bookmarks: wget --spider --force-html -i bookmarks.html This feature needs much more work for Wget to get close to the functionality of real web spiders.

Documentation: https://www.gnu.org/software/wget/manual/wget.pdf

Calcariferous answered 29/9, 2022 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.