Forum Moderators: bakedjake

Message Too Old, No Replies

cron question

stupid newbie

         

Doood

3:01 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



I'm trying to run a maintenance script every hour from root, but I'm a newbie to linux and it's not easy to understand at first. I don't think it's working correctly so I'm running it twice each hour and sending the log of one of them to root to find errors. (domain name has been replaced)

This is what is in crontab -l
1 * * * * wget -q -O /dev/null [<website>.com...]
31 * * * * wget -q -O [<website>.com...]

When I go into pine to check root email, I find this message hourly and the url is highlighted in it. (I thought I changed it to send root emails to my email but apparently not)

Subject: Cron <root@hah01> wget -q -O [<website>.com...]
wget: missing URL
Usage: wget [OPTION]... [URL]...

There is also a daily cron email called run-parts /etc/cron.daily that has some errors in it but doesn't mention anything about the above cron job. Could I put this cron job in /etc/cron.hourly and run it that way?

I don't really know if I'm doing this all wrong or what.

Doood

3:04 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



also, when I go into the actual script at my site to see if the maintenance.php is being run, it only show up as running at 00:01, once a day everyday

wruk999

4:26 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



Hi Doood,

Are you trying to actually run the PHP page, so that it runs any commands inside the PHP page?

To achieve this, there are two ways - call the file through the php binary (I could not get it to work this way on my server)

OR

as I have done, create a shell script, with the command:


lynx -dump http://www.website.co.uk/myscript.php

And then in the cron, simply put:

1 * * * * /path/to/shell/file/shell.sh
31 * * * * /path/to/shell/file/shell.sh

I think this will be the easiest way for you - but this will only work if the lynx browser is installed on your server.
Try from a command prompt:
whereis lynx
and see what response you receive ;)

wruk9999

Doood

5:44 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



I'm trying to run the maintenance script for phpAdsNew and the manual for it says to put one of the following in the crontab

# if your server supports curl:
0 * * * * curl -s -o /dev/null [your.server.name.here...]
# if your server supports fetch:
0 * * * * fetch -o /dev/null [your.server.name.here...]
# if your server supports lynx:
0 * * * * lynx > /dev/null -dump [your.server.name.here...]
# if your server supports wget:
0 * * * * wget -q -O /dev/null [your.server.name.here...]

Is the manual for phpAdsNew wrong or does this mean that I need to use your method because the other way doesn't work on my server.

wruk999

7:02 pm on Oct 29, 2003 (gmt 0)

10+ Year Member



# if your server supports lynx:
0 * * * * lynx > /dev/null -dump [your.server.name.here...]

Here it is ;)

I just don't put the >/dev/null 'cause I want the output, and also, I put it in a .sh (shell) script because I run a couple of other scripts at the same time.

I also find it easier to run one shell script with as many commands in, than adding them all to the crontab file.

To check whether your server supports lynx, run the whereis lynx command and see whether it has it.

Personally, I prefer the lynx command over wget - but thats a personal preference. (But it was also the only thing that worked for my case.)

wruk999

Doood

10:13 pm on Oct 30, 2003 (gmt 0)

10+ Year Member



I think that worked. It's sending hourly emails with the lynx crontab as the subject and nothing inside the message. I guess that means it's working correctly.

wruk999

9:54 pm on Nov 1, 2003 (gmt 0)

10+ Year Member



Doood,

The server sends out an email for every successful crontab run. The output is in the body, and if your script has executed successfully, and doesn't print anything back to the issuing browser (lynx) then the body of your email will be blank.

If your sending these emails regularly (like twice an hour I think you said) then you may want to turb them off - they could become very annoying. To do so, you can add >& /dev/null to the end of the line inside the crontab file.

So, if you set it up as shown earlier in this thread, inside your crontab, you can have:

1 * * * * /path/to/shell/file/shell.sh >& /dev/null
31 * * * * /path/to/shell/file/shell.sh >& /dev/null

Add this and reload the cron daemon, and you should stop receiving the emails every time the script is run.

wruk999

Doood

2:07 pm on Nov 3, 2003 (gmt 0)

10+ Year Member



I don't know how to make a shell script so I just used the lynx command in the crontab. I figured both ways did the same thing.

Thanks for the help wruk999.