1748134 Members
3652 Online
108758 Solutions
New Discussion юеВ

Re: crontab

 
Tarek_1
Frequent Advisor

crontab

Hi,
i need to make a crontab that executes a script every night
at 4 am. What is the right crontab format?
I have made a man of crontab and cron, but it doesn't explain how to put the hour and how to execute it.
Thanks in advance.
4 REPLIES 4
Craig Kelley
Valued Contributor

Re: crontab

00 04 * * * username /path/to/program some args go here
Stuart Browne
Honored Contributor

Re: crontab

Craig's entry would work well if using 'Vixie' crond, and the '/etc/crontab' file.

If using an older style of cron, or not using '/etc/crontab', then you'd just drop the 'username' field.

The 'crontab' command will actually take you into an editor to modify the user's crontab if you don't specify a file. If doing that, you'll want to make sure the user you are adding the crontab for doesn't already have one, or if they do, that you also include them in your update.

The following commands might be useful to you:
# List 's current crontab
crontab -l -u
# Edit (using '$VISUAL') crontab for
crontab -e -u

'man crontab' lists these. For the format of the 'crontab' files, you'll want to read 'man 5 crontab'.

On most systems, the default '$VISUAL' editor is '/bin/vi'. If you aren't familier with Vi, you might want to change that, and the '$EDITOR' environment variables to something you are more comfortable with.
One long-haired git at your service...
Francisco J. Soler
Honored Contributor

Re: crontab

See man 5 crontab, you will find the right crontab format.

Frank.
Linux?. Yes, of course.
I_M
Honored Contributor

Re: crontab

FYI, if you are using RedHat Linux, some program such as logrotate, updatedb and so on.
So I think you better start your program before or after 4AM.

#crontab -l list current schedule.

Good luck