0

During the test of my script.

The cronjob should run a script through the browser every 2 minutes. So I had the following cron:

*/2 * * * * wget -O http://192.10.10.1/mypage/myscript.php

The cron run a couple of times before I changed it to:

0 1 * * * wget -O http://192.10.10.1/mypage/myscript.php

to run the script everyday at 1am but it does not work.

I am a bit confused why the first one successfully run my script while the latter didn't. What am I doing wrong? Or what could possibly be the reason why running it at 1am does not work?

1 Answers1

0

As pointed out in a comment above, the most obvious pbm is that you are not using the -O option correctly.

Look up man wget in terminal. Here is an extract:

-O file
--output-document=file.
The documents will not be written to the appropriate files, but all will be concatenated together and written to "file". If - is used as file, documents will be printed to standard output (stdout), disabling link conversion. Use ./- to print to a file literally named -.

Use of -O is analogous to shell redirection:
wget -O file http://foo is intended to work like wget -O - http://foo > file; where "file" will be truncated immediately, and all downloaded content will be written there.

If, as a non root user, you run a GUI cmd or direct yr output to stdout in an already running X session, make sure yr cron environment knows about the active display. To make cron GUI aware, i.e. to tell it, what display the program should use (:0 is the default in a desktop environment)

0 1 * * * export DISPLAY=:0; XAUTHORITY=~/.Xauthority /usr/bin/wget -O - http://192.10.10.1/mypage/myscript.php

or, if you want to set the DISPLAY environment variable ONLY for a specific cmd:

0 1 * * * DISPLAY=:0 XAUTHORITY=~/.Xauthority /usr/bin/wget -O - http://192.10.10.1/mypage/myscript.php

or, if redirecting output to a file for later perusal, the need to specify the correct display disappears because nothing actually goes to stdout :

0 1 * * *  /usr/bin/wget -O <filename> http://192.10.10.1/mypage/myscript.php

The latter solution makes more sense, if you run yr cron job at 1am and you are not sitting in front of yr desktop display.

==
Let us known in case of continuing problems.

Cbhihe
  • 2,801
  • 3
  • 27
  • 47