8

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

Community
  • 1
  • 1
Mohamed Mehanny
  • 187
  • 1
  • 5
  • 19
  • 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? – Frank Schmitt Oct 18 '16 at 10:08
  • @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 ?? – Mohamed Mehanny Oct 18 '16 at 10:32
  • 1
    Instead of redirecting the output to /dev/null, redirect it to a log file, e.g. via `command > /tmp/cron-log.txt` – Frank Schmitt Oct 18 '16 at 10:36
  • @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 :) – Mohamed Mehanny Oct 18 '16 at 11:20

5 Answers5

17

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
Saeed Awan
  • 416
  • 6
  • 8
  • can we also use like `GET https://example.com/billing/?ng=console/0982995697/` ?? –  Mar 05 '20 at 14:25
  • 1
    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`. – adejones Feb 18 '21 at 08:51
4

Alternative try this

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

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

Ejeh
  • 425
  • 5
  • 7
2

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

1

You can use "links" command like:

links https://www.honeymovies.com
Abdul Alim
  • 110
  • 7
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

BogdanPopa
  • 305
  • 2
  • 5