Talk:Crontab

From DreamHost
Jump to: navigation, search

Problems for novice users

I'm fairly novice at using the unix shell and when I followed these instructions I had problems. Firstly, I found that by creating a text file and editing my crontab using the command "crontab cron.txt", the job never executed unless I put a carriage return at the end of the cron.txt file after the command I wanted to execute. Next I found that when the line in my cron.txt file ended with >/dev/null, I still received an email when the job executed successfully.

After emailing Dreamhost support, I was advised to change the end of the line to 2>/dev/null 1>&2. I await this evening's run to see if this stops the email being sent. I don't want to change this article myself because I don't really know what I'm talking about with cron, but this article isn't enough for a novice like me to set up a cron job properly on the first try.

-William

Thanks for the comments. I added a couple things to try to make it more clear (good luck with that!). Also, MAILTO="" in the cron file is supposed to prevent email, although I haven't tried it. Feel free to change what you know or learn. It's easy to fix if it turns out to be incorrect. :-) --Pseudomonad 08:57, 8 Nov 2006 (PST)

Either adding >/dev/null 2>&1 to the end of a crontab line or adding MAILTO="" as the first crontab 'entry' will prevent mail from being sent.

UNIX processes can produce output on the "standard output" stream and also on the "standard error" stream. Sending only one of the streams to /dev/null (a blackhole device which eats up any input) isn't sufficient to guarantee there will be no output. That's what the 2>&1 line does. It sends the standard error stream to standard out, and the whole lot is sent to the bit bucket (/dev/null). --Kingboyk 04:51, 11 Nov 2006 (PST)

Persistent process

Is there any way to have a process become persistent? I.e. it restarts every time the server reboots?

Alternatively, could someone provide some PHP code for a process to check if an instance of itself is already running and exit if so? (What I'm hoping to come up with is a site updating script/process.) --Kingboyk 04:53, 11 Nov 2006 (PST)

"Persistent processes" have been strongly discouraged and may be killed automatically. Limits are not published to my knowledge, but probably involve system load and cpu time. Processes scheduled to run with cron should automatically run again, next time scheduled, even after server reboots. --Pseudomonad 14:51, 11 Nov 2006 (PST)
Thanks. The process I have in mind shouldn't fall foul of those guidelines, and isn't sinister in any way. Looks like cron will be the way to go though. --Kingboyk 05:37, 13 Nov 2006 (PST)

PHP: Adding a line to the top of the script

The article says:

To execute a PHP script using crontabs, you must add this line to the top of the PHP script you want to execute for it to work:

#!/usr/local/bin/php -q

However, it does not say whether to add this before the initial "<?php" tag or after... --Wikitonic 11:16, 3 December 2007 (PST)

PHP: Crontab via Control Panel

Can someone add a tried and tested working example of the text you should insert into 'Command to run' when setting up a new Cron via the Dreamhost control panel. In addition, if they could clarify:

1. if they added '#!/usr/local/bin/php -q' to the php file (documentation says this is not needed)

2. needed to ensure certain permissions type for the php file

I have tried numerous variations based on info here and elsewhere and nothing seems to work. --Nycmstar 09:37, 3 June 2008 (PDT)

What timezone are dreamhost crobtab hours?

Looks like my dreamhost server is running in PST. Does this mean that a 0 in the hour slot will launch the cron listing at midnight PST? Davious (talk)

Yes. Dreamhost is primarily based in Los Angeles, so the server times are all set to PST. A 0 in the hour slot corresponds to 12am Pacific. Ryan C (talk) 20:16, 9 November 2012 (PST)